title: Codeigniter form validation - forms value always disappeared
body: <p>I'm making a form input in codeigniter with validation. The form validation work fine (if all form are empty), but if i give the value only in 1 or 2 form (there is an empty form) then click the submit(save) button, the value in form always disappeared.</p>
  
  <p>My <strong>Controller-function Save</strong></p>
  
  <pre><code>function save($is_update=0) {
  
          $data['nik']            = $this-&gt;input-&gt;post('nik', true);
          $data['nmdepan']        = $this-&gt;input-&gt;post('nmdepan', true);
          $data['nmlengkap']      = $this-&gt;input-&gt;post('nmlengkap', true);
          $data['username']       = $this-&gt;input-&gt;post('username', true);
          $data['password']       = $this-&gt;input-&gt;post('password', true);
          $data['leveluserid']    = $this-&gt;input-&gt;post('leveluserid', true);
          $data['jabid']          = $this-&gt;input-&gt;post('jabid', true);
  
          $this-&gt;_set_rules();
          if ($this-&gt;form_validation-&gt;run() == true) {
              if($is_update==0) {
                  if($this-&gt;M_menu_user-&gt;insert($data))
                      redirect('master/user/C_menu_user');
              } else {
                  $id = $this-&gt;input-&gt;post('id');
                  if($this-&gt;M_menu_user-&gt;update_by_id($data, $id))
                      redirect('master/user/C_menu_user');
              }
          }
      }
  </code></pre>
  
  <p><strong>Controller-function _set_rules</strong></p>
  
  <pre><code>function _set_rules() {
          if($this-&gt;session-&gt;userdata('logged_in')) {
              $session_data            = $this-&gt;session-&gt;userdata('logged_in');
              $data['username']        = $session_data['username'];
              $data['password']        = $session_data['password'];
              $data['jabid']           = $session_data['jabid'];
              $data['leveluserid']     = $session_data['leveluserid'];
  
              $LevelUser  = $session_data['leveluserid'];
              $username   = $session_data['username'];
  
              $menus = $this-&gt;M_menu-&gt;menus($LevelUser);
              $data2 = array('menus' =&gt; $menus);
  
              $this-&gt;load-&gt;library('form_validation');
  
  
              $this-&gt;form_validation-&gt;set_rules('nik','NIK','required|max_length[10]');
              $this-&gt;form_validation-&gt;set_rules('nmdepan','Nama Depan','required|max_length[30]');
              $this-&gt;form_validation-&gt;set_rules('nmlengkap','Nama Lengkap','required|max_length[30]');
              $this-&gt;form_validation-&gt;set_rules('username','Username','required|max_length[15]');
              $this-&gt;form_validation-&gt;set_rules('password','Password','required|max_length[30]');
              $this-&gt;form_validation-&gt;set_rules('leveluserid','Level ID User','required|max_length[10]');
              $this-&gt;form_validation-&gt;set_rules('jabid','ID Jabatan','required|max_length[10]');
  
              $this-&gt;form_validation-&gt;set_message('required', '%s &lt;font color="red"&gt;&lt;strong&gt;Harus Diisi.&lt;/strong&gt;&lt;/font&gt;');
  
              if ($this-&gt;form_validation-&gt;run() == FALSE) {
                  $this-&gt;data['is_update'] = 0;
                  $this-&gt;load-&gt;view('master/user/V_menu_form_user', array_merge($data, $data2,$this-&gt;data));
              } else {
                  $this-&gt;data['is_update'] = 0;
                  $this-&gt;load-&gt;view('master/user/V_menu_form_user', array_merge($data, $data2,$this-&gt;data));
  
              }
          } else {
  
                  redirect('C_login', 'refresh');
          }       
      }
  </code></pre>
  
  <p>Here is my <strong>view</strong></p>
  
  <pre><code>&lt;?php
    $this-&gt;load-&gt;view('template/head');
  ?&gt;
  
  &lt;!--custom css--&gt;
  &lt;!-- iCheck --&gt;
  &lt;link href="&lt;?php echo base_url('assets/AdminLTE-2.0.5/plugins/iCheck/flat/blue.css') ?&gt;" rel="stylesheet" type="text/css" /&gt;
  
  
  &lt;?php
    $this-&gt;load-&gt;view('template/topbar');
    $this-&gt;load-&gt;view('template/sidebar');
  ?&gt;
  
  
  &lt;!-- Content Header (Page header) --&gt;
  &lt;!-- Main content --&gt;
  &lt;section class="content"&gt;
  &lt;?php  
  
      if(!empty($query)) {
          $row = $query-&gt;row_array();
      } else {
  
          $row['userid']      = '';
          $row['nik']     = '';
          $row['nmdepan']     = '';
          $row['nmlengkap']   = '';
          $row['username']    = '';
          $row['password']    = '';
          $row['leveluserid']     = '';
          $row['jabid']       = '';
      }
  
      echo "&lt;div class='row'&gt;
              &lt;div class='col-md-12'&gt;
                  &lt;div class='box box-primary'&gt;
                      &lt;div class='box-header'&gt;
                          &lt;h3 class='box-title'&gt;FORM USER&lt;/h3&gt;
                      &lt;/div&gt;                
  
                          &lt;div class='box-body'&gt;";
  
                              echo form_open('master/user/C_menu_user/save/'.$is_update);
  
                              echo form_hidden('id',$row['userid']);
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;NIK&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('nik',$row['nik'],"maxlength='10' class=form-control").form_error('nik'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;Nama Depan&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('nmdepan',$row['nmdepan'],"maxlength='30' class=form-control").form_error('nmdepan'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;Nama Lengkap&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('nmlengkap',$row['nmlengkap'],"maxlength='30' class=form-control").form_error('nmlengkap'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;Username&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('username',$row['username'],"maxlength='15' class=form-control").form_error('username'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;Password&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('password',$row['password'],"maxlength='30' class=form-control").form_error('password'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;Level ID User&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('leveluserid',$row['leveluserid'],"maxlength='10' class=form-control").form_error('leveluserid'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo "&lt;div class='row'&gt;
                                      &lt;div class='col-lg-12'&gt;
                                          &lt;div class='form-group'&gt;";
                                          echo "&lt;label class='col-sm-2 control-label'&gt;ID Jabatan&lt;/label&gt;
                                                &lt;label class='col-sm-1 control-label'&gt;:&lt;/label&gt;
                                                  &lt;div class='col-sm-3'&gt;".form_input('jabid',$row['jabid'],"maxlength='10' class=form-control").form_error('jabid'). "&lt;/div&gt;";
                                      echo "&lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt; &lt;br&gt;";
  
                              echo form_submit('btn_save','Simpan',"class='btn btn-primary'");
  
                              echo "&lt;a href=".site_url('master/user/C_menu_user')." class='btn btn-success'&gt;Kembali&lt;/a&gt;";
  
  
                             echo form_close();
                          echo "&lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;";  
  
  ?&gt;
  
  &lt;/section&gt;&lt;!-- /.content --&gt;
  &lt;?php
  $this-&gt;load-&gt;view('template/js');
  ?&gt;
  
  &lt;!--custom js --&gt;
  &lt;!-- Sparkline --&gt;
  &lt;script src="&lt;?php echo base_url('assets/AdminLTE-2.0.5/plugins/sparkline/jquery.sparkline.min.js') ?&gt;" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;?php
  $this-&gt;load-&gt;view('template/foot');
  ?&gt;
  </code></pre>
  
  <p>look at this pictures, i've filled in 3 form.
  <a href="https://i.stack.imgur.com/Uwel7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Uwel7.png" alt="enter image description here"></a></p>
  
  <p>Then i click button <strong>"Simpan"</strong>, the form value will be disappear. <em>(Simpan = Save/Submit and Kembali = Back/Cancel</em>). So i need to start again fill the forms. <a href="https://i.stack.imgur.com/g0pe9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g0pe9.png" alt="enter image description here"></a>  </p>
  
  <p>The validation work fine if all form are empty.
  <a href="https://i.stack.imgur.com/nTtlr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nTtlr.png" alt="enter image description here"></a></p>
  
  <p>How to keep the value stay in form ? did i make a wrong form validation ?</p>
  
  <p>Thanks!</p>