• 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?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

The native way is to use NSURLConnection (have a look at the docs or google for examples). But there are loads of third party libraries that a lot of people use such as ASIHTTPRequest and AFNetworking.

Link to comment
Share on other sites

  • 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?

Link to comment
Share on other sites

  • 0

I got this reply:

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...

Link to comment
Share on other sites

  • 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

Link to comment
Share on other sites

  • 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!

Link to comment
Share on other sites

This topic is now closed to further replies.