Note that there are some explanatory texts on larger screens.

plurals
  1. POValidating sections of a form
    primarykey
    data
    text
    <p>I've broken my form up into divs and using Next buttons to shop and hide those sections. I am also using jQuery Validation Plugin to do all the validation for me.</p> <p>What I need to know is how to validate section by section. So this is what I have</p> <ol> <li>Personal Information</li> <li>Address details</li> <li>Project Information</li> <li>Terms and conditions</li> </ol> <p>2,3,and 4 are hidden by default to make the form less daunting.</p> <p>Clicking on the next button of Personal Information will hide this div and show the Address Details and so on.</p> <p>The very last screen has the submit form button which then would validate the entire form normally but I need to validate each section before the user moves on.</p> <p>Here's what I thought should have worked:</p> <p><strong>CSS</strong></p> <pre><code> .project-address {display:none;} </code></pre> <p><strong>HTML</strong></p> <pre><code> &lt;form class="wpcf7"&gt; &lt;div class="project-details"&gt; &lt;h2&gt;Project details&lt;/h2&gt; &lt;label&gt;Project name: &lt;/label&gt;&lt;input type="text" class="reg-project-name" size="40" value="" name="projectName"&gt; &lt;div class="back-next"&gt;&lt;span class="reg-next-button"&gt;Next&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="project-address"&gt; &lt;h2&gt;Project address&lt;/h2&gt; &lt;label&gt;Project address:&lt;/label&gt;&lt;input type="text" class="reg-project-address" size="40" value="" name="projectAddress"&gt; &lt;div class="back-next"&gt;&lt;span class="reg-next-button"&gt;Next&lt;/span&gt;&lt;/div&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p><strong>JQUERY</strong></p> <pre><code> //clicking the next button hides this section and shows the next section jQuery('.project-details .reg-next-button').click(function() { // jQuery(".project-details").slideUp(); // jQuery('.project-address').slideDown(); jQuery('.reg-project-name').validate({ debug: true, rules: { projectName: "required" }, messages: { projectName: "Please give your project a name", } }); }); </code></pre> <p><strong>EDIT: Have tried to validate one element like this.</strong></p> <pre><code> jQuery('.project-details .reg-next-button').click(function() { // jQuery(".project-details").slideUp(); // jQuery('.project-funding').slideDown(); var validator = jQuery( ".wpcf7-form" ).validate(); validator.element( ".reg-project-name" ); }); </code></pre> <p><strong>EDIT:</strong> If I click on the Next button, I need the form elements to be validated in that div before moving on which is not happening. i.e the form elements are not being validated..</p> <p>Any thoughts? Many thanks.</p>
    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.
 

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