• 0

[Xcode/Objective-C] Submitting Data to URL


Question

I created an iPhone app and used Interface Builder to create a form with three textboxes and a Submit button. How can I take the data from the textboxes and submit (via POST) to a URL?

5 answers to this question

Recommended Posts

  • 0

^ Thanks. I've been doing some research but am still stuck... I posted the question on StackOverflow (http://stackoverflow.com/questions/8945453/using-nsurlconnection-to-post-data-to-php-script), but I'll re-post it here, too: I'm completely new to Objective-C and XCode. I created a Single-View application for an iPhone. On the view are 3 textboxes and a button. I need to have the button POST data to a PHP script, and the data is coming from the 3 textboxes. I have been told to use NSURLConnection, but I am not sure how to implement it.

Can somebody please help me?

  • 0

I got this reply:

  Quote
ou could use ASIHTTPRequest using it in this way:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:someUrl];

[request setRequestMethod:@"POST"];

[request setPostValue:@"..." forKey:@"user"];

[request setPostValue:@"..." forKey:@"password"];

[request setDelegate:self];

[request startAsyncrhonous];

and in php called in someUrl you get variable ( EXAMPLE )

$user = $_POST['user'];

$password = $_POST['password'];

Is more simple using ASIHTTPRequest instead NSURLConnection

But I'm still not sure how to implement it using values from textboxes and calling it from a button press...

  • 0

you need to make sure you have a reference to the UILabel in your code (using an IBOutlet and hooking it up in interface builder) then you need to create a method thats an IBAction and hook that up to the button. then literally pop in that sample code and pull the data from the textboxes.

http://www.raywenderlich.com/tutorials start at the top :) will really help you out to learn the basics

  • 0

If you have set up your UITextField's correctly you will be able to use the values like so: self.theTextField.text.

Setup a button:


-(IBAction)doSomething:(id)sender {
// code
}
[/CODE]

You would then need to link the button in Interface Builder.

If you aren't getting the results you would expect then NSLog will be your friend throughout development.

Simply add an NSLog statement inside a method you aren't sure is being called etc like so NSLog(@"This should show in console");

This allows you to print things out to console and can help you solve almost anything!

This topic is now closed to further replies.
  • Posts

    • Yeah, I totally get your point, which is possible it could happen. I just hope there is a few people around him who are similar to where if they took over things would run pretty much the same. if not, then yeah, it could start to decline rapidly etc. but I figure something that's been around for a longer period of time with a decent backing, and probably more users than most Linux distro's (which I would 'imagine' Mint is one of the more used Linux desktop distro's by volume of people who use it), is less likely to just disappear. but like you said, nothing is guaranteed. but I do think you are probably right in that Clem is probably the core of what keeps Mint, Mint. I like how it tends to stay pretty much the same with some slight tweaks here and there (but is largely the same) instead of that crap some people go for with change for the sake of change trying to create a overly fancy interface and other unnecessary stuff etc. I also feel Mint keeps a nice balance of things out-of-the-box where it's not too bloated, nor too striped down. p.s. but I see Mint as a better Ubuntu basically. but I get your point like if it was more of a really serious choice of needing a 'safe bet' to use long term, then yeah something like official Ubuntu would be one of the better choices for sure given what you said with it being backed by an actual company which makes it a safer bet than Mint which is smaller and 'could' potentially be more fragile.
    • It’s in development so hopefully it’s improved upon before release.
    • For the 10th iteration they could have bothered with some design changes rather than just carrying over the 9's
    • So this requires hardware to be setup in the area you want to listen to music in? And it requires hardware for each user? So useless for me when I'm out walking my dog? Or when I'm at the gym and want to listen to my podcasts rather than the music the gym is broadcasting? Heck, will it even work in my own home and allow me to walk around from room to room, or even within a room? Yeah, these won't be replacing headphones anytime soon.
  • Recent Achievements

    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
    • Explorer
      cekicen went up a rank
      Explorer
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      211
    3. 3
      Michael Scrip
      200
    4. 4
      Xenon
      147
    5. 5
      +FloatingFatMan
      122
  • Tell a friend

    Love Neowin? Tell a friend!