title: Setting value of radio button in Codeigniter
body: <p>In my form for editing details, I have a radio button with values <code>0</code> and <code>1</code>. What I want is, while the form is loaded ie, when user clicks on <code>edit</code> link, the radio button should be set to the value in the database. Once the user have changed it and submit the form, it should retain the submitted value. How this is possible ?</p>
  
  <p>I tried with the below code and it doesn't worked. I know that it can't be done this way. <code>$row-&gt;videotype</code> have the value from database.</p>
  
  <pre><code>&lt;input type="radio" name="trailer" value="1" &lt;?php 
      if(set_radio('trailer', '1', TRUE)) {
          echo set_radio('trailer', '1', TRUE); 
      } else { 
          if($row-&gt;videotype==1) ?&gt; checked=checked &lt;?php 
      } ?&gt; /&gt;Yes
  &lt;input type="radio" name="trailer" value="0" &lt;?php 
      if(set_radio('trailer', '0')) {
          echo set_radio('trailer', '0');  
      } else {
          if($row-&gt;videotype==0) ?&gt; checked=checked &lt;?php 
      } ?&gt; /&gt;No
  </code></pre>
  
  <p>In form submission function (in controller) , I have set this for form validation :</p>
  
  <pre><code>$this-&gt;form_validation-&gt;set_rules('trailer', 'Trailer', 'is_numeric');  
  </code></pre>
  
  <p>Can anyone help me to fix this? Thanks in advance.</p>