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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

jquery validate failing...


Go to End


3 Posts   918 Views

Avatar
JonShutt

Community Member, 244 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, 1391 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
JonShutt

Community Member, 244 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...