title: CodeIgniter: How can I retain values after an invalid form submission?
body: <p>I've Googled and there are many ways of doing this in PHP itself, JavaScript/ jQuery/ AJAX and CodeIgniter session data/ flash data.</p>
  
  <p>But I prefer to have do this within PHP. My form is very large and contains different elements like text inputs, dropdowns, radios, etc. However I tried the following on my inputs in the View (MVC).</p>
  
  <p>Example:</p>
  
  <pre><code>&lt; input type="radio" name "gender" value="Male" &lt;?php echo ($gender == 'Male')? 'checked': ''; ? /&gt;
  &lt; input type="radio" name "gender" value="Female" &lt;?php echo ($gender == 'Female')? 'checked': ''; ? /&gt;
  </code></pre>
  
  <p>This gives an error on page load, obviously because the $gender variable is not defined. I can fix this issue in Controller but it will be a huge process and fragment the code. Are there any alternative ways? Examples are welcome!</p>