views:

356

answers:

0

I have a UIWebView that is typically browsing a J2EE application but I have a hardcoded check in shouldStartLoadWithRequest: to find the string "mobile_get_photo" in the URL and if present push a new view controller onto the navigation controller that allows a user to select an image via the photo library or the phone.

The mobile_get_photo is sent through something like:

<form method="post" action="mobile_get_photo">
  <input type="hidden" name="option" value="get_photo" />
  <input type="submit" value="Get Photo From Phone" />
</form>

Once the user is happy with the photo they have selected they touch a save button. The save button creates an NSURLRequest object, and writes a multipart form HTTP post message, and sends it to the server. I also copy everything submitted through the form into my post (I just want to pass the variable option="get_photo_" through to the server). The server then sends a response which I capture through:

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog([[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]);

Okay, so here is the weirdness. On my response page, I have a similar form to the previous one. It looks something like:

<form method="post" action="some_real_server_action">
  <input type="hidden" name="option" value="save_photo" />
  <input type="submit" value="Save Photo" />
</form>

I have verified through the NSLog above that this is indeed the HTML that my iPhone app is receiving. Immediately after the NSLog above I call:

[mainController.webView loadHTMLString:returnString baseURL:[NSURL URLWithString:_the_url];

Strangely the submit button (which should read "Save Photo" reads "Get Photo From Phone" and when I submit the value of option sent to the server is "get_photo" not "save_photo").

If I change, for instance, option on one of the pages to be type="text" then the problem goes away, but if I change both options to type="text" the problem is back. Also, I made the second form look like this:

<form method="post" action="some_real_server_action">
  <input type="hidden" name="option" value="save_photo" />
  <input type="submit" value="Save Photo" />
  <input type="submit" value="Save Photo" />
</form>

In this case the first submit button read "Get Photo From Phone" while the second submit button read "Save Photo"... I have no idea what to do at this point. Any ideas?