Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you need to change a bit how you it works. Don't try to achieve blocking, but embrace non-blocking.</p> <p>I would do like this: - Keep the validation on email; make it Asynchronous. When it's valid, set a flag somewhere in a variable to know it's ok. - Add a callback on the form.submit() to check whether the email is ok (with the variable) and prevent the submission if it's not.</p> <p>This way you can keep asynchronous call without freeze the web browser UI.</p> <p>-- [edit] -- </p> <p>This is some quick code I just wrote for the example based on what you already have.</p> <p>For your information, a programming notion called "promises" (futures and deferred are other terms for it) has been invented to solve exactly the problem you have.</p> <p>Here's an article on what it is and how to use them in JavaScript (using dojo or jQuery): <a href="http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx" rel="nofollow">http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx</a> </p> <pre><code>&lt;script&gt; function validateEmailRegistered(input) { if (input.setCustomValidity === undefined) return; var err = 'Email address not found'; $.ajax({ url: 'email-is-registered.php', data: { email: input.value }, success: function(data) { var ok = data=='true'; input.setCustomValidity(ok ? '' : err); // If the form was already submited, re-launch the check if (form_submitted) { input.form.submit(); } } }); } var form_submitted = false; function submitForm(form) { // Save the user clicked on "submit" form_submitted = true; return checkForm(form); } function checkForm(form, doSubmit) { if (doSubmit) { form_submitted = true; } // If the email is not valid (it can be delayed due to asynchronous call) if (!form.email.is_valid) { return false; } return true; } &lt;/script&gt; &lt;form method="get" action="nextpage.php" onsumbit="return submitForm(this);"&gt; &lt;input name="email" id="email" type="email" required onChange="validateEmailRegistered(this)"&gt; &lt;button type="submit"&gt;go&lt;/button&gt; &lt;form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload