title: Codeigniter: Form validation when updating records
body: <p>I'm having a tough time getting this to work. Maybe my logic is all wrong, but I figure someone with more experience can help me.</p>
  
  <p>I have a page "<a href="http://domain.com/account/settings" rel="nofollow noreferrer">http://domain.com/account/settings</a>" where users can edit their account information. When the form submits, it triggers the "settings_save" method. All is fine if the form submits successfully, however, in the event one of the field doesn't validate, the URL remains at "<a href="http://domain.com/account/settings_save" rel="nofollow noreferrer">http://domain.com/account/settings_save</a>" I actually want it to stay on <a href="http://domain.com/account/settings" rel="nofollow noreferrer">http://domain.com/account/settings</a>"</p>
  
  <p><strong>account.php</strong> controller</p>
  
  <pre><code>function settings() {
      $data['records'] = $this-&gt;account_model-&gt;getAccountSettings("sam");
      $this-&gt;load-&gt;view('account_settings_view', $data);
  }
  
  function settings_save() {
      $this-&gt;load-&gt;library('validation');
  
      $records['email']   = "trim|required|min_length[4]|xss_clean";
      $records['gender']  = "trim|required|xss_clean";
      $records['seeking'] = "trim|required|xss_clean";
      $records['marital_status']  = "trim|required|xss_clean";
      $records['kids']    = "trim|required|xss_clean";
      $records['drinking']    = "trim|required|xss_clean";
      $records['smoking'] = "trim|required|xss_clean";
      $records['ethnicity']   = "trim|required|xss_clean";
      $records['body_type']   = "trim|required|xss_clean";
      $records['zipcode'] = "trim|required|min_length[5]|numeric|xss_clean";
  
      $this-&gt;validation-&gt;set_rules($records);
  
      if ($this-&gt;validation-&gt;run() == false)
      {
          $this-&gt;load-&gt;view('account_settings_view', $records);                   
      }
  
      else
      {
          $records = array();
          $records['email'] = $this-&gt;validation-&gt;email;
          $records['gender'] = $this-&gt;validation-&gt;gender;
          $records['seeking'] = $this-&gt;validation-&gt;seeking;
          $records['marital_status'] = $this-&gt;validation-&gt;marital_status;
          $records['kids'] = $this-&gt;validation-&gt;kids;
          $records['drinking'] = $this-&gt;validation-&gt;drinking;                     
          $records['smoking'] = $this-&gt;validation-&gt;smoking;
          $records['ethnicity'] = $this-&gt;validation-&gt;ethnicity;
          $records['body_type'] = $this-&gt;validation-&gt;body_type;
          $records['zipcode'] = $this-&gt;validation-&gt;zipcode;       
  
          $this-&gt;account_model-&gt;saveAccountSettings("sam", $records);
          $this-&gt;session-&gt;set_flashdata('message', 'Done. You have added new task.');            
  
          redirect('account/settings');
          //redirect('account/settings');
      }
  }
  </code></pre>
  
  <p><strong>account_settings_view.php</strong> view</p>
  
  <p>I have the following line:</p>
  
  <pre><code>&lt;?=form_open('account/settings_save');?&gt;
  </code></pre>