Problems coding for form_radio() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Problems coding for form_radio() (/showthread.php?tid=29747) |
Problems coding for form_radio() - El Forum - 04-20-2010 [eluser]Wayne Smallman[/eluser] Hi guys! I'm trying to code up radio buttons, but it's not working out. Code: $input_common['cash'] = array ( In the form, I have: Code: <dt><?php echo form_label('Cash?', $input_common['cash']['id']); ?></dt> However, while they're being grouped, it's not checking cash (there isn't even a checked attribute) and their values are being set to Array. The help documentation isn't all that helpful in terms of syntax. Just saying that form_radio() is almost the same as form_checkbox() isn't as instructive as actually providing code for the grouping, values etc. Any ideas? Problems coding for form_radio() - El Forum - 04-20-2010 [eluser]mddd[/eluser] You are mixing up the two uses of form_radio: 1. form_radio($name, $value, $checked_or_not); 2. form_radio($array_of_attributes); If you provide an array for the attributes of the radio button (method 2), then you should not provide the name separately. So your form code should be: Code: <?php echo form_radio($input_common['cash']); ?> Problems coding for form_radio() - El Forum - 04-20-2010 [eluser]Wayne Smallman[/eluser] Guys, I've figured it out, and there were two things to consider. In the first instance, I was doing some checking of values (this page handles both adding and editing), and I had the checking aspect the wrong way around. Code: $input_common['cash'] = array ( In the second instance, form_radio() doesn't appear to like being supplied an array as the second argument. So I supplied actual values for each argument instead. Code: <dt><?php echo form_label('Cash?', $input_common['cash']['id']); ?></dt> Problems coding for form_radio() - El Forum - 04-20-2010 [eluser]Wayne Smallman[/eluser] [quote author="mddd" date="1271779253"]You are mixing up the two uses of form_radio: 1. form_radio($name, $value, $checked_or_not); 2. form_radio($array_of_attributes); If you provide an array for the attributes of the radio button (method 2), then you should not provide the name separately. So your form code should be: Code: <?php echo form_radio($input_common['cash']); ?> Hi! I just replied, but didn't see your reply first. As I said, it's not totally clear in the documentation. Thanks all the same. Problems coding for form_radio() - El Forum - 04-20-2010 [eluser]Wayne Smallman[/eluser] Hi guys, I have another problem — how do I get the page to "remember" the values of the radio buttons? So far, all of the other form elements work fine using set_value(), but I can't figure out how to make form_radio() work the same way as the others. Is there a way to combine the form_radio() with set_radio() functions? I've been trying, but no joy so far. Problems coding for form_radio() - El Forum - 04-21-2010 [eluser]bhogg[/eluser] set_radio() isn't really designed for use with form_radio but rather with a manual <input type="radio" ... /> tag. The hack of a workaround is something like (replacing users/dashboard with your form): Code: <div> I just put $this->load->library('form_validation'); in the controller to get this working. Problems coding for form_radio() - El Forum - 04-21-2010 [eluser]Pascal Kriete[/eluser] You can still use set_value(), you just need to compare it to what you expect to get: Code: <?php echo form_radio("testing", "val1", (set_value("testing") == "val1") ); ?> VAL1<br /> |