Radiant mailer form jQuery validation


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

jQuery client-side form validation for the Radiant CMS mailer extension.
Requires jQuery 1.2.6+
Each required field needs a class of "required" assigned to the input tag.


Copy this code and paste it in your HTML
  1. //Contact form valiadation
  2. var form = $("form#contact-form");
  3.  
  4. form.submit(function(event) {
  5. form.find('label.error').filter('[generated=true]').empty();
  6.  
  7. if ( ((req_fields = form.find('.required[value=""]')).length > 0) || (form.find('select.required option:selected').val = "") ) {
  8. //req_fields.before('<p class="error" generated="true">This field is required</p>')
  9. req_fields.before('<span class="error" generated="true">This field is required</span><br />');
  10. $(req_fields).css('background', 'red');
  11. req_fields[0].focus();
  12. return false;
  13. } else {
  14. return true
  15. }
  16. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.