Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-12-2009, 11:29 PM   #1 (permalink)
DenVog
Registered Member
 
DenVog's Avatar
 
Join Date: Jan 2009
Location: Silicon Valley, USA
Posts: 624
DenVog is on a distinguished road
Question Posting Form with Hidden Field

I am trying to use NSURLConnection to submit a form to a URL. My form requires the inclusion of a hidden field with a specific name and value. In HTML it would look like:
Code:
 <form action="http://www.example.com/mail" enctype="multipart/form-data" method="POST">
 <input type="text" name="mailfrom">
 <input type="hidden" name="sendtoemail" value="destination-webmaster@example.com">
 <input type="submit" value="Send Email">
 </form>
I've found several threads on submitting general text fields (e.g. UITextField for entering an email address), but nothing covering how to include a hidden field that requires a specific name and value. Here's what I have so far:
Code:
NSString *post = nil;  
post = [[NSString alloc] initWithFormat:@"message=%@",messageText.text];  
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];  
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];  
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];  
[request setURL:[NSURL URLWithString:@"http://www.example.com/mail"]];  
[request setHTTPMethod:@"POST"];  
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];  
[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];  
[request setHTTPBody:postData];  
[ NSURLConnection connectionWithRequest:request delegate:self ];  
[post release];

Thanks for any assistance.

PS-Am I going to run into trouble using "multipart/form-data" for the Content Type, instead of "application/x-www-form-urlencoded" which I see in most of the examples?
DenVog is offline   Reply With Quote
 

» Advertisements
» Online Users: 633
19 members and 614 guests
007007, ADY, appsman, baja_yu, Bertrand21, clarky07, dacapo, dhun, flamingliquid, GHuebner, greeneye82, jaystudio, marleneZ, talyn4, tapan.raju, thorb65, trisvandis, TylerBetable, ukneeq
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,182
Threads: 93,921
Posts: 402,158
Top Poster: BrianSlick (7,968)
Welcome to our newest member, appsman
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.