Using Dreamweaver Spry validation with jQuery ajax form plugin
Writing form validation code manually is a boring task. Not only that, editing or adding new fields each time and modifying the validation code accordingly is such a pain. When Dreamweaver added the Spry form validation with CS3 the nightmare is over. The greatest feature of using it is you can do the form validation work automatically with a couple of mouse clicks and no hand written code! And you can easily change/edit or add/remove the fields.
I know jQuery has simple validation plugin but you have to write the codes for it, which is time consuming. I always use the spry validation of dreamweaver as I learned using it for it’s simplicity. When I tried to use it with the jQuery ajax form submit plugin I got disappointed. It didn’t work! I didn’t stop trying. And finally I found the way which I’m gonna share with you :)
Here is the simple code that you need in the “beforeSubmit” parameter of $.ajaxForm
$("#formID").ajaxForm({
url: "submit.php",
beforeSubmit: function(formData, jqForm, options){
if (Spry) { // checks if Spry is used in your page
var r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
if (!r)
return r;
}
},
success: successFunction,
complete: completeFunction
});
Hope that’ll help a lot boosting your web development.




My Elance Profile
Recent Comments