Basic checkbox validation not working - grad students + please help!!! |
[eluser]CIfan1000[/eluser]
I have the following controller: Code: <?php With the following view: Code: <h1>Checkbox test</h1> And I do not get a validation message if I do not check the checkbox and press Submit. I did at one time when I had the validation rule originally set to "required" and it worked. The problem with using "required" originally was that the validation message was " The User agreement checkbox field must have a value. I would like it to say: The User agreement checkbox field is required. So then I changed it to "isset". That didnt work (no validation message). Then I changed it back to "required" and now this also doesn't provide a validation message. Maybe a bug? I have spent 6 hours today trying different things including writing the above code to isolate it only to a checkbox. I have also tried a callback function that also doesnt work. I am starting to tear my limited amount of hair out!!! Any help I would be very grateful for!!!!!
[eluser]Pascal Kriete[/eluser]
Can't spot anything wrong at first glance. Could it be the language file? Is the file loaded? What happens if you use a string there instead. [/code] $this->validation->set_message('isset', 'You must accept the terms'); [/code]
[eluser]CIfan1000[/eluser]
Hi inparo, Thanks for the suggestion. I made the change in my controller and unfortunatley it did not make a difference. I edited my post above to reflect the change in the controller. Please let me know if you have any other suggestions.
[eluser]Pascal Kriete[/eluser]
Ah, I'm silly. Validation will only run if the $_POST array has at least one value. So as is it won't work if the checkbox isn't set, since that means that there is no POST data. Try naming your submit button, or add another field to the form.
[eluser]CIfan1000[/eluser]
Yes! That worked! Thank you, thank you! However, it didnt work quite the way I expected. I added the name to the submit button: Code: <div><input type="submit" name="SubmitButton" value="Submit" /></div> I am not sure why this would happen, but I changed the rule to "required", and then the validation worked properly, but the validation message for the "isset" was shown. Code: $this->validation->set_message('isset','Please read and agree to the User Agreement.'); Again, I am not sure why this would happen.... But I read that one should use "required|isset": Code: $rules['CheckboxUserAgreement'] = "required|isset"; I tried this and now I still get the validation message for the "isset". But I am happy with this. I very much appreciate you helping me out on this!
[eluser]hvalente13[/eluser]
Some changes are commited in the svn version of codeigniter. You may want to check it out and see if the Validation Class permits you to do what you want. I've not tested it but it's worth to try it. SVN Repository
|
Welcome Guest, Not a member yet? Register Sign In |