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.
What I need to know is how to validate section by section. So this is what I have
- Personal Information
- Address details
- Project Information
- Terms and conditions
2,3,and 4 are hidden by default to make the form less daunting.
Clicking on the next button of Personal Information will hide this div and show the Address Details and so on.
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.
Here's what I thought should have worked:
CSS
.project-address {display:none;}
HTML
<form class="wpcf7">
<div class="project-details">
<h2>Project details</h2>
<label>Project name: </label><input type="text" class="reg-project-name" size="40" value="" name="projectName">
<div class="back-next"><span class="reg-next-button">Next</span></div>
</div>
<div class="project-address">
<h2>Project address</h2>
<label>Project address:</label><input type="text" class="reg-project-address" size="40" value="" name="projectAddress">
<div class="back-next"><span class="reg-next-button">Next</span></div>
</div>
</form>
JQUERY
//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",
}
});
});
EDIT: Have tried to validate one element like this.
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" );
});
EDIT:
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..
Any thoughts?
Many thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…