set_radio() function not repopulating my radio buttons. Can't figure out why |
[eluser]iamzvonko[/eluser]
Hello, I have a form with several radio button groups. My problem is that I can't get it to re-populate the selected radio button in each group. Here's a snippet for one of the groups. The $days variable is an array of arrays. Each array entry contains some information about a specific day. Code: <?php For text input fields I use the set_value('name') function and it works fine. Well, it works fine as long as I have a validation rule for each text field. Found out that I had to have an empty validation rule if in fact I didn't need to validate the field just so it would get repopulated. Thinking along this line, I thought I needed to add an empty validation rule for the radio button so I added this: Code: $this->form_validation->set_rules('volDate', 'Date', ''); Still no luck. When I submit the form and have to re-display it because of errors on other fields, my selected radio button is now un-selected. Any idea how I can get around this? Thanks!
[eluser]iamzvonko[/eluser]
None that I can see. Here's the log file. The 5:23 entries are from initial load. The 5:25 entries are from the submit after I selected a radio button. Do you see anything that stands out as unusual in this? Code: DEBUG - 2012-01-18 05:23:32 --> Config Class Initialized
[eluser]Matt S.[/eluser]
Funny how something so simple could cause so much confusion...you forgot to add an echo before set_radio()! Code: <?php echo set_radio('volDate', $val);?>/>
[eluser]iamzvonko[/eluser]
Well, not so fast. I was really excited when I saw that last reply last night because it seemed like just a stupid programmer error. I can deal with that. I had shut down my PC by then and I haven't been able to get back to it until now (gotta work for a living during the day). So I put in the echo but STILL no luck. Then I went back to basics. I built the form controller and view as described in CI documentation here. I just added some radio buttons explicitly (without loop as in my code) and it repopulated the proper radio button on submit. Then I added another radio button group but generated it with a loop this time. Worked like a charm also. As long as I had an empty validation rule in controller. That made me think "maybe I just typed something wrong in my validation rule". Checked and checked but I just don't see it. Sorry for the long post but I'm pulling out what little hair I have left. Any help would be greatly appreciated. Here's the sample form controller and view that works just fine FORM CONTROLLER Code: <?php FORM VIEW Code: <html> Now here are snippets of my code that does NOT work: CONTROLLER Code: ... VIEW Code: ...
[eluser]Philip Kavanagh[/eluser]
If you want to validate a radio input, you should check for the "on" status rather than the "checked". Simply create a new callback or extend CI_Form_validation lib. you would build a proper callback here, but im just making it clear here... Code: function is_on($input)
[eluser]iamzvonko[/eluser]
I'm not really concerned with validating it. I just want it to repopulate the correct radio button in the group when I submit the form and come back to it. Or am I misunderstanding what you're suggesting? |
Welcome Guest, Not a member yet? Register Sign In |