0

I'm trying to handle a click button here : Link button Here is the code :

<form action="/contest-voting/" method="post" id="pimp-entities-contest-voting-form" accept-charset="UTF-8"><div><input type="hidden" name="nid" value="1200">

<input type="hidden" name="fb_id" value="">

<input type="hidden" name="form_build_id" value="form-iZa3h_R56jG3BZpQCaktyWo8exlP8PnURETJEm0omUk">

<input type="hidden" name="form_id" value="pimp_entities_contest_voting_form">
Nutze deinen <input type="image" id="edit-facebook" name="facebook" value="Per Facebook abstimmen" src="http://www.pimp-your-school.de/sites/all/themes/pimp_foundation/images/icon-voting-fb.png" class="form-submit">-Account oder deine <div class="form-item form-type-textfield form-item-email">

<input placeholder="E-Mail-Adresse" type="text" id="edit-email" name="email" value="" size="60" maxlength="128" class="form-text">

<input type="image" id="edit-submit" name="submit" value="Per E-Mail-Adresse abstimmen" src="http://www.pimp-your-school.de/sites/all/themes/pimp_foundation/images/icon-voting-3.png" class="form-submit"></div></form>

I have tried all this StackOverflow links which are not working :

Identify submit button click of UIWebview,

Grabbing POST data from UIWebView,

UIWebView capture post,

Swift UIWebView shouldStartLoadWithRequest doesn't fire in iOS8,

Call swift function with javascript using UIWebview

Any other ways ?

Community
  • 1
  • 1
Antoine
  • 1,139
  • 9
  • 21

1 Answers1

0

I cannot tell by your question if you are trying to submit the form or observing when it gets submitted. But if you are trying to submit the form you can do this.

func webViewDidFinishLoad(_ webView: UIWebView) {

    // This adds an email to the email text field. This takes the id of the email text field.
    webView.stringByEvaluatingJavaScript(from: "document.getElementById('edit-email').value = \"example@example.com\"")

    // This submits the field. This takes the id of the form.
    webView.stringByEvaluatingJavaScript(from: "document.getElementById('pimp-entities-contest-voting-form').submit()")

}

I am not sure how to observe the form being submitted because the

func webViewDidStartLoad(_ webView: UIWebView)

doesn't seem to be called when the form is submitted, because usually, you would use this function when the url changes. It should change to http://www.pimp-your-school.de/contest-voting/ but this doesn't seem to be the case.

Tristan Beaton
  • 1,742
  • 2
  • 14
  • 25
  • Hey, I'm trying to observe and not to submit. As you say the link is not called which is very strange. Any ideas ? Anyway, thanks for your answer ! – Antoine Apr 26 '17 at 15:43
  • I don't know much about web forms, but it seems that when the button is clicked, the web page is doing a post request, rather than the browser. So a new URL isn't being loaded. I've played around with the UIWebView Delegate but none of them are being called. So unless your web page is changed to load the post URL, I don't think UIWebView is sophisticated enough to do what you want. – Tristan Beaton Apr 27 '17 at 04:26
  • Yep I arrived to this conclusion too... Thank you very much ! – Antoine Apr 27 '17 at 05:31