validation, radio button, and loops? - 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: validation, radio button, and loops? (/showthread.php?tid=11183) |
validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]alanphil[/eluser] In my view I'm creating a list of concerts, like this: Code: <?php foreach ($concerts as $row): ?> I'm trying to add validation to keep the selected radio button selected, if some other field fails validation. I've tried many variations of the following from the user guide: Code: <input type="radio" name="myradio" value="1" <?php echo $this->validation->set_radio('myradio', '1'); ?> /> When I try the following, the radio button isn't set after validation: Code: <?php echo $this->validation->set_radio('concert_selection', "<?=$row->id?>"); ?> I've tried many variations of the above. What am I missing? Alan validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]Thorpe Obazee[/eluser] maybe you can use Code: if ($_POST) { something like that... validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]alanphil[/eluser] Thanks Chamyto, but if possible, I'd like to use the set_radio method as defined in the user guide. Is there an issue with using dynamic data in the set_radio method? Thanks, Alan validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]Thorpe Obazee[/eluser] Code: if ($_POST) { the above won't work on radio buttons. you will need to echo a 'selected' so.... set_radio() Code: <?php foreach ($clients->result() as $client):?> the above is if there is something selected from the database already. Code: <?php foreach ($clients->result() as $client):?> this one is if there is none. validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]Thorpe Obazee[/eluser] I reviewed your code a bit and saw something. [quote author="alanphil" date="1220043107"]In my view I'm creating a list of concerts, like this: Code: [code]<?php echo $this->validation->set_radio('concert_selection', "<?=$row->id?>"); ?> I've tried many variations of the above. What am I missing? Alan[/quote] Code: <?php echo $this->validation->set_radio('concert_selection', $row->id); ?> I believe that's what you were missing validation, radio button, and loops? - El Forum - 08-29-2008 [eluser]alanphil[/eluser] Thanks Chamyto! I thought it might be something I overlooked, and having you review this was much appreciated. Works great now! Alan |