Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

jquery validate failing...


Reply


3 Posts   541 Views

Avatar
Futureweb

Community Member, 233 Posts

29 September 2011 at 9:01pm

Hi,

I've followed the details here: http://www.ssbits.com/tutorials/2009/using-jquery-for-form-validation/
but my form is being submitted no matter what I choose...

unfortunately the default validation doesn't seem to work with tick boxes, so i'm having to cancel that and use a custom script

the page is live here: http://gvnpods.org/become-a-member/signup

can anyone see anything that might be stopping my jquery validation working?

Cheers

Avatar
martimiz

Forum Moderator, 1132 Posts

29 September 2011 at 11:16pm

I think you should use the fieldname to define rules and messages, instead of the the field id:

jQuery("#Form_SignupForm").validate({
   rules: {
      Form_SignupForm_Email: { required: true, email: true        },
      Form_SignupForm_LastName: { required: true },
      ...

becomes

jQuery("#Form_SignupForm").validate({
   rules: {
      Email: { required: true, email: true        },
      LastName: { required: true },
      ...

Hope that helps...

Avatar
Futureweb

Community Member, 233 Posts

29 September 2011 at 11:38pm

Thanks, I'll give that a try tomorrow - late now!

in the mean time I went back to the standard validation script and added this

jQuery("#Form_SignupForm_TC").click(function(){
         
   // If checked
   if (jQuery("#Form_SignupForm_TC").is(":checked")){
      jQuery("#Form_SignupForm_Terms").val("yes")
   }else{
      Query("#Form_SignupForm_Terms").val("")
}

this crudely gets around the tick box issue by setting a value to a hidden field. silverstripe vaidlates the hidden field instead of the tickbox. the problem is that when you submit the form, you get the error messages. when you tick the box to correct the issue, the error message isn't being removed - it must be getting triggered by onkeydown or somthing...