title: Codeigniter Form Validation...form re-population
body: <p>I am in the process of creating an input form on a record specific page e.g. (property/rentals/rec_id). On submission, the data should be inserted, validated and return to the original page from which it was sent with any relevant messages. </p>
  
  <ul>
  <li>If the validation fails, reload the form page a re-populate the form</li>
  <li><p>Echo the specific validation error - e.g. invalid email address etc</p></li>
  <li><p>If successful, insert data, reload the page and display success message.</p>
  
  <p>function class() {</p>
  
  <pre><code>$this-&gt;load-&gt;library('form_validation');    
  $this-&gt;form_validation-&gt;set_rules('name','name','required|trim');
  $this-&gt;form_validation-&gt;set_rules('email','email','required|trim|valid_email');
  
  $fields['name'] = 'Name';
  $fields['email'] = 'Email Address';
  
  $this-&gt;validation-&gt;set_fields($fields);
  
  if ($this-&gt;form_validation-&gt;run() == FALSE) 
  {
      //failed - reload page and re-populate fields with any error messages
  }
  else
  {
       // display form with success message
  }
  </code></pre>
  
  <p>}</p></li>
  </ul>
  
  <p>Normally this is simply done by 'loading a view' and passing the relevant data to repopulate the page, fields or display messages. But I have to use a 'redirect' back to the product specific page. Is there any good way to do this other than using session data to carry the validation errors..?</p>
  
  <p>Thanks in advance, Michael</p>