Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are various approaches to stepped forms.</p> <p>When I create multi-step forms, I use a unique set of <code>&lt;form&gt;</code> tags for each section. Then I use <a href="http://jqueryvalidation.org/valid/" rel="nofollow noreferrer">the <code>.valid()</code> method</a> to test the section before moving to the next. <em>(Don't forget to first initialize the plugin; call <code>.validate()</code>, on all forms on DOM ready.)</em></p> <p>Then on the last section, I use <code>.serialize()</code> on each form and concatenate them into a data query string to be submitted.</p> <p>Something like this...</p> <pre><code>$(document).on('pageinit', function() { // dom ready handler for jQuery Mobile $('#form1').validate({ // initialize form 1 // rules }); $('#gotoStep2').on('click', function() { // go to step 2 if ($('#form1').valid()) { // code to reveal step 2 and hide step 1 } }); $('#form2').validate({ // initialize form 2 // rules }); $('#gotoStep3').on('click', function() { // go to step 3 if ($('#form2').valid()) { // code to reveal step 3 and hide step 2 } }); $('#form3').validate({ initialize form 3 // rules, submitHandler: function (form) { // serialize and join data for all forms var data = $('#form1').serialize() + '&amp;' + $('#form2').serialize() + '&amp;' + $(form).serialize() // ajax submit return false; // block regular form submit action } }); // there is no third click handler since the plugin takes care of this // with the built-in submitHandler callback function on the last form. }); </code></pre> <p>Important to remember that my <code>click</code> handlers above are not using <code>type="submit"</code> buttons. These are regular buttons, either <em>outside</em> of the <code>form</code> tags or <code>type="button"</code>.</p> <p>Only the button on the very last form is a regular <code>type="submit"</code> button. That is because I am leveraging the plugin's built-in <code>submitHandler</code> callback function on only the very last form.</p> <p><strong>"Proof of Concept" DEMO: <a href="http://jsfiddle.net/8bnZV/" rel="nofollow noreferrer">http://jsfiddle.net/8bnZV/</a></strong></p> <p><strong>BTW</strong>, notice how I replaced your outdated <code>.bind()</code> with the more modern <code>.on()</code> method. </p> <p>Also, see for reference:</p> <p><a href="https://stackoverflow.com/a/17975061/594235">https://stackoverflow.com/a/17975061/594235</a></p>
 

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