Welcome Guest, Not a member yet? Register   Sign In
Radio Button Validation Problem
#1

[eluser]Xiphar[/eluser]
Hi
I am validating a form that has a radio button. I am using the Validator library to validate the radio buttons.
However, I have noticed that the validator does not do a 'required' validation on the radio button if I have not clicked any of the radio buttons. I even have callback functions defined, but it seems that the functions are not called by the validator.

Any guesses why, and any workarounds you know?

Thanks
Xiphar
#2

[eluser]tonanbarbarian[/eluser]
Can you supply some code?

Are all of your radio buttons the same name?
If they are then it should return a value if one is set and therefore the required validation should work.

Please post your view and your validation rules
#3

[eluser]Michael Ekoka[/eluser]
Hey Xiphar, I'm sending you a pm with an updated Validation library. Just place it in your application/libraries directory it should overwrite the native Validation lib. Let me know if it fixes your problem.
#4

[eluser]Nick Husher[/eluser]
Er? Is that a good idea?

Is the member named CodeIgniter an actual CI developer? Also, it's usually better to extend existing functionality than overwrite it. Creating a library called ext_Validator or my_Validator that builds on Validation would would be a better solution.
#5

[eluser]Michael Ekoka[/eluser]
Quote:Creating a library called ext_Validator or my_Validator that builds on Validation would would be a better solution.

This is why Xiphar will receive a MY_Validation.php file that he can simply put in his application/libraries directory. If it doesn't work he can just remove it.
#6

[eluser]zauber[/eluser]
When you say "overwrite" I'm pretty sure you meant "override"
#7

[eluser]Xiphar[/eluser]
Hey CodeIgniter..
Thanks a lot man.. the extended library works beautifully.
Just out of curiousity, what is the problem with the existing validation class?

Xiphar
#8

[eluser]Michael Ekoka[/eluser]
Quote:When you say “overwrite” I’m pretty sure you meant “override”

My mistake. Thanks for the correction zauber.

Quote:Thanks a lot man.. the extended library works beautifully.
Just out of curiousity, what is the problem with the existing validation class?

You're welcome Xiphar. What is the problem with the existing validation? There are a few actually, but to be specific about radio buttons, the validation relies on what was submitted in the POST to apply its rules. When empty form elements are submitted, the POST will usually contain variables corresponding to these element and set to the empty string, except for unchecked radios and checkboxes which return nothing at all (no name nor value), as if they were not even in the form. These last 2 elements have to be treated specially. The original validation mechanism simply "forgot" to enter the individual error message for these special cases.

There are many issues that the core Validation library doesn't handle as expected. I created a thread about it, when I posted my modifications. I don't go into details about why it doesn't work, I just explain briefly what was missing before that the library can handle now.

Read about what the modified library can do, in addition to what was explained in the CI User Guide.

Anyways, play around with the library, if you find some issues let me know.
#9

[eluser]Xiphar[/eluser]
Hey CodeIgniter
Thanks a lot.. that was really helpful.
And yah, the new functions you have added are really helpful. I have a file upload in my form and I don't want to upload the file if there are errors elsewhere. I'm guessing I can make use of your functions.
Your error message above is funny 'Hey Monkey....' Sometimes I do feel like writing such messages but of course I can't..!
#10

[eluser]Michael Ekoka[/eluser]
No you can't :lol:. On a side note I've uploaded the file to a public server and made it available in the old thread.




Theme © iAndrew 2016 - Forum software by © MyBB