tags:

views:

39

answers:

1

Hi,

I use a form in a UIWebView in my iPhone application that initially is blank. After the user enters his name for the first time, I would like to store that information and use it for future form submissions, from the same app of course. Does this have to happen through javascript or from the iPhone API? I read about NSHTTPCookie and I'm not sure if this is what I want to use..

Thanks for any suggestion!

A: 

If you are storing the HTML source for the form locally, then the easiest thing to do will be to modify the HTML source to include the inital values of the input elements.

For example, you can store the HTML as an NSMutableString and modify it as needed. You can load it into the webview using the loadHTMLString method of UIWebView.

Emil
The page with the form will be online (but in my server) so I guess your approach wouldnt' work, right?
Irene
Using cookies is explained here: http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/URLLoadingSystem/URLLoadingSystem.html
Emil
Another way to do what you want is to use the stringByEvaluatingJavaScriptFromString method of UIWebView to set the appropriate variables in your page. This may be the easiest way to do it.
Emil
good, i mark this as an answer, stringByEvaluatingJavaScriptFromString seems to work fine. thanks!
Irene