// Wait for the DOM to be ready
$(function() {
// Initialize form validation on the registration form.
// It has the name attribute "registration"
$("form[name='registration']").validate({
// Specify validation rules
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
firstname: "required",
lastname: "required",
email: {
required: true,
// Specify that email should be validated
// by the built-in "email" rule
email: true
},
password: {
required: true,
minlength: 5
}
},
// Specify validation error messages
messages: {
firstname: "Please enter your firstname",
lastname: "Please enter your lastname",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
},
email: "Please enter a valid email address"
},
// Make sure the form is submitted to the destination defined
// in the "action" attribute of the form when valid
submitHandler: function(form) {
form.submit();
}
});
});
Source β
But this based on when an action of the form is normal, but I am using AJAX to submit form here.
I have changed the script a bit. I was googling and stumbled upon this.
Actually, I have made a lot of changes in the script since my first post here.
By default, there was certain kind of validations in the script(Popup validations) but initially, they were not working. I struggled for around 10 days to send email through the form, and finally, I was able to send email through Ajax and WP mail function.
But now when I was trying to validate the form by using the model given in the Github link that I have shared above β The Jquery validation(the pop validations, which were not previously working) suddenly started working in its entirety. But if you look I was only trying to validate the first name as a test, but now the whole validation is working that was already present in the original JS file.
But the Ajax is not working. So we have two possibilities now β
Number one β list of older validation work but at the same time, AJAX part should also be functional to send an email.
Number two β the older validation should stop working and Our new test validation should work along with the Ajax.
off-topic: the type attribute for a script tag is unnecessary for Javascript; it is the default and assumed contents of any script tag.
The error on line 8350 (or in your base code, 8819) that Paul is pointing you towards is because submitHandler is not a function to be called, it is a member of the object passed to validate. its form should be submitHandler: function(form) { .....
I have rectified the error in the original code, but still the same. Once the form is fully filled the page refreshes that means this part is executing β
Weβre going to be hard pressed to verify your javascript output when youβre showing us the raw code that is designed to be parsed through a PHP engine first.
Update your test page, and we can view source on the output.