CodeIgniter Forums
radio button validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: radio button validation (/showthread.php?tid=30639)



radio button validation - El Forum - 05-21-2010

[eluser]ommy[/eluser]
I'm stabbing in the dark here.
How am i supposed to set up a working validation for a few radiobuttons.

Let's say i have this in my view:
Code:
<input type="radio" name="voor" value"1"> Part one
<input type="radio" name="voor" value"2"> Part two

then i would have this in my controller:
Code:
$this->load->library('form_validation');
$this->form_validation->set_rules('voor','radio','required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('formwithradios')
}else{
echo 'hoorai';
}

The main problem i'm experiencing is that the value of the post variable is "ON" when something is selected. and false when nothing has been. I can imagine set_radio having trouble finding which radio button it should select after submitting/failing validation.


radio button validation - El Forum - 05-21-2010

[eluser]ommy[/eluser]
for some reason i wasn't getting the right response from the validation class.
I got it to work but i'm still wondering what my mistake was.
Form validation has this knack of bugging me every time i use it Smile

this is working:
Code:
<input type="radio" name="voor" value="1" <?=set_radio('voor','1',true)?> />

still registering the radio buttons:
Code:
$this->form_validation->set_rules('voor');

So if anyone would care to enlighten me what i did wrong or could've done wrong in the first place.

Thanks a bunch and sorry for my semi-irrelevant question