Welcome Guest, Not a member yet? Register   Sign In
set_radio() function not repopulating my radio buttons. Can't figure out why
#5

[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
class Form extends CI_Controller {
function index()  {
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->form_validation->set_rules('email', 'Email', 'required');
  $this->form_validation->set_rules('volDate', 'volDate', '');
  $this->form_validation->set_rules('volDate2', 'volDate2', '');
  if ($this->form_validation->run() == FALSE) {
   $this->load->view('myform');
  } else {
   $this->load->view('formsuccess');
  }
}
}
?>

FORM VIEW
Code:
<html>
<head>
<title>My Form</title>
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<h5>Email Address</h5>
&lt;input type="text" name="email" value="&lt;?php echo set_value('email'); ?&gt;" size="50" /&gt;
<h5>Explicit</h5>
&lt;input type="radio" value="Mon" name="volDate" id="volDate" &lt;?php echo set_radio('volDate', "Mon");?&gt;/&gt;Monday&nbsp;&nbsp;
&lt;input type="radio" value="Tue" name="volDate" id="volDate" &lt;?php echo set_radio('volDate', "Tue");?&gt;/&gt;Tuesday&nbsp;&nbsp;
&lt;input type="radio" value="Wed" name="volDate" id="volDate" &lt;?php echo set_radio('volDate', "Wed");?&gt;/&gt;Wednesday&nbsp;&nbsp;
&lt;input type="radio" value="Thu" name="volDate" id="volDate" &lt;?php echo set_radio('volDate', "Thu");?&gt;/&gt;Thurday&nbsp;&nbsp;
&lt;input type="radio" value="Fri" name="volDate" id="volDate" &lt;?php echo set_radio('volDate', "Fri");?&gt;/&gt;Friday&nbsp;&nbsp;
<h5>With Loop</h5>
&lt;?php
$days2 = array("dateID" => 1, "day" => "Mon");
array_push($days2, array("dateID" => 2, "day" => "Tue"));
array_push($days2, array("dateID" => 3, "day" => "Wed"));
array_push($days2, array("dateID" => 4, "day" => "Thu"));
array_push($days2, array("dateID" => 5, "day" => "Fri"));
foreach ($days2 as $day2) {
  $val2 = $day2['dateID'];
?&gt;
&lt;input type="radio" value="&lt;?php echo $val2;?&gt;" name="volDate2" id="volDate2"&lt;?php echo set_radio('volDate2', $val2);?&gt;/&gt;&lt;?php echo $day2['day']; ?&gt;&nbsp;&nbsp;
&lt;?php } ?&gt;
<div>&lt;input type="submit" value="Submit" /&gt;&lt;/div>
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Now here are snippets of my code that does NOT work:
CONTROLLER
Code:
...
$this->form_validation->set_rules('volDate', 'Date', '');
    $this->form_validation->set_rules('volSite', 'Site', '');
...

VIEW
Code:
...
&lt;?php
echo "<b>Step 1: Select a date</b><br />&nbsp;&nbsp;";
foreach ($days as $day) {
  $val = $day['dateID'];
?&gt;
&lt;input type="radio" value="&lt;?php echo $val;?&gt;" name="volDate" id="volDate"&lt;?php echo set_radio('volDate', $val);?&gt;/&gt;&lt;?php echo $day['day']; ?&gt;&nbsp;&nbsp;
&lt;?php } ?&gt;
<br>
&lt;?php
echo "<br /><b>Step 2: Select a location</b><br />&nbsp;&nbsp;";
foreach ($sites as $site) {
  $val = $site['siteID'];
  echo '&lt;input type="radio" value="'.$val.'" name="volSite" id="volSite"&gt;'.$site['name'].set_radio('volSite', $val).'&nbsp;&nbsp;';
}
?&gt;
...


Messages In This Thread
set_radio() function not repopulating my radio buttons. Can't figure out why - by El Forum - 01-18-2012, 07:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB