Validate + submit form


/ Published in: jQuery
Save to your folder(s)

Valiodate a form with jQuery.Validate and submit it with jQuery.form


Copy this code and paste it in your HTML
  1. $(document).ready(function(){
  2. var f = $("#signup_form").validate({
  3. rules: {
  4. firstname: "required",
  5. lastname: "required",
  6. email: {
  7. required: true,
  8. email: true
  9. },
  10. comment: {
  11. maxlength: 200
  12. }
  13. },
  14. submitHandler: function(form) {
  15. $("#signup").ajaxSubmit({
  16. success: showResponse
  17. });
  18. return false;
  19. }
  20. });
  21. function showResponse(responseText, statusText, xhr, $form) {
  22. f.resetForm();
  23. $('.msg').html('Thank you, your message was successfully sent');
  24. }
  25. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.