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 ?

1 Answer 1

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 = \"[email protected]\"")

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

Sign up to request clarification or add additional context in comments.

3 Comments

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 !
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.
Yep I arrived to this conclusion too... Thank you very much !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.