title: Codeigniter- How to preserve form values if error on submit
body: <p>I have the form field like</p>
  
  <pre><code>&lt;input type="text" class="form-control" name="postal_code" id="form_control_1" value="&lt;?php if($user-&gt;postal_code   === NULL) { echo set_value('postal_code');} else { echo $user-&gt;postal_code;} ?&gt;"&gt;
  &lt;label for="form_control_1"&gt;Postal Code&lt;/label&gt;
  &lt;span class="help-block"&gt;Postal Code is required&lt;/span&gt;
  </code></pre>
  
  <p>and my function is</p>
  
  <pre><code>public function postProfile() {
      if ($_POST) {
  
  
          $this-&gt;form_validation-&gt;set_rules('postal_code', 'Postal Code', 'required');
          $this-&gt;form_validation-&gt;set_rules('gender', 'Gender', 'required');
          $this-&gt;form_validation-&gt;set_rules('country', 'Country', 'required');
          $this-&gt;form_validation-&gt;set_rules('month', 'Month', 'required');
          $this-&gt;form_validation-&gt;set_rules('day', 'Day', 'required');
          $this-&gt;form_validation-&gt;set_rules('year', 'Year', 'required');
          $this-&gt;form_validation-&gt;set_rules('mobile_number', 'Mobile Number', 'required');
  
  
          if ($this-&gt;form_validation-&gt;run() === FALSE) {
  
              //$this-&gt;session-&gt;set_flashdata('err', validation_errors());
              $this-&gt;session-&gt;set_flashdata('email_err', form_error('email'));
              $this-&gt;session-&gt;set_flashdata('postal_code_err', form_error('postal_code'));
              $this-&gt;session-&gt;set_flashdata('gender_err', form_error('gender'));
              $this-&gt;session-&gt;set_flashdata('country_err', form_error('country'));
              $this-&gt;session-&gt;set_flashdata('day_err', form_error('day'));
              $this-&gt;session-&gt;set_flashdata('year_err', form_error('year'));
              $this-&gt;session-&gt;set_flashdata('month_err', form_error('month'));
              $this-&gt;session-&gt;set_flashdata('mobile_err', form_error('mobile_number'));
              redirect('profile/' . $this-&gt;session-&gt;userdata['front']['id']);
          } else {
  
              $dob = $this-&gt;input-&gt;post('month') . '/' . $this-&gt;input-&gt;post('day') . '/' . $this-&gt;input-&gt;post('year');
              $userData = array(
                  'email' =&gt; $this-&gt;input-&gt;post('email'),
                  'date_of_birth' =&gt; $dob,
                  'gender' =&gt; $this-&gt;input-&gt;post('gender'),
                  'country' =&gt; $this-&gt;input-&gt;post('country'),
                  'mobile_number' =&gt; $this-&gt;input-&gt;post('mobile_number'),
                  'postal_code' =&gt; $this-&gt;input-&gt;post('postal_code'),
              );
  
  
              $updateUser = $this-&gt;user-&gt;updateUser($this-&gt;session-&gt;userdata['front']['id'], $userData);
              if ($updateUser) {
                  $this-&gt;session-&gt;set_flashdata('err', '&lt;div class="alert alert-success"&gt;Profile Updated Successfuly&lt;/div&gt;');
                  redirect('profile/' . $this-&gt;session-&gt;userdata['front']['id']);
              } else {
                  echo "Un expected error ";
                  exit;
              }
          }
      } else {
          $this-&gt;logout();
      }
  }
  </code></pre>
  
  <p>but value is not shown for the postal code field in case of validation errors</p>