Form Tools
Radio Button Group Validation Not Working - Printable Version

+- Form Tools (
+-- Forum: Modules / Other (
+--- Forum: Form Validation: JS + PHP (
+--- Thread: Radio Button Group Validation Not Working (/showthread.php?tid=1501)

Radio Button Group Validation Not Working - robidigital - Aug 3rd, 2011


I have the following JS validation rules setup -

var rules = [];
rules.push("required,Recruitment_Source,Please select a Recruitment Source.");
rules.push("required,Name_First,Please enter your first name.");
rules.push("required,Name_Last,Please enter your last name.");
rules.push("required,email,Please enter your email address.");
rules.push("valid_email,email,Please enter a valid email address.");

The first rule for field named "Recruitment_Source" is a set of radio buttons. If I leave them all unselected, and leave the other required fields blank and submit the form, the browser jumps to the radio buttons as though it is about to alert that the field is required, but instead it continues to the thank you page.

If I remove the radio button group from the rules, validation works fine on all of the other text input fields. Having the validation on the radio buttons basically breaks all validation.

Seems like a bug. Any ideas?

Thanks in advance,

RE: Radio Button Group Validation Not Working - Ben - Aug 4th, 2011

Hi Ryan,

Yeah, that does sound rather like a bug - but I'd be rather surprised, because I've used it to validation radio button groups countless times. So maybe it's an incompatibility with a newer browser? It sounds like it's focusing on the field then throwing some sort of error - or not returning false (just to check, your onsubmit handler is like this, correct? onsubmit="return rsv.validate(this, rules)" ).

Would you mind trying it on a different browser to see if it still occurs? If it occurs on another browser as well than it's a bug. Otherwise, it's more likely an idiosyncracy of your form.

Do you have a link to the page?

- Ben

RE: Radio Button Group Validation Not Working - robidigital - Aug 5th, 2011

Hi Ben,

My form tag looks like this -
<form action="/form-new.php" method="POST" onsubmit="return rsv.validate(this, rules)">

Also it does occur in various browsers.

I'll PM a link to the form.


RE: Radio Button Group Validation Not Working - Ben - Aug 5th, 2011

Hi Ryan,

Thanks for sending me a link to the form - it took a little puzzling though, but I found out the problem.

It's actually not so much a problem with the RSV library as the modification I tell you to make in the documentation, to make it compatible with the modifications I made to the RSV script bundled in the core.

To fix it, change this line:
rsv.errorFieldClass = null;

to this:
rsv.errorFieldClass = "";

That should make all errors mysteriously vanish...! Smile

Sorry for the headache. I'll have to update the documentation.

- Ben

RE: Radio Button Group Validation Not Working - robidigital - Aug 8th, 2011

Good find! Thanks for the fix! Smile

RE: Radio Button Group Validation Not Working - 01tbgt - Oct 1st, 2020

These rules are easy to understand and the input method is so convenient, thanks to you in advance. My further interest is the can we implement this routine at for further development of code and secure login of the users?