reusability - How to reuse form in codeigniter for update and add -


hello want reuse form in codeigniter problem update form populated 1 page has load. here sample form.

 <?php    $attributes = array('class' => 'form-horizontal', 'id' => 'addpersonnel');   echo form_open($form_submission, $attributes);   ?>         <input type="text" name="name" value="<?php echo set_value('name')?"> >         <input type="text" name="rank" value="<?php echo set_value('rank')?"> >         <button type="submit" class="btn btn-primary">save</button>                                                    <?php echo form_close()?> 

my problem here lies in set_value() method of form_validation class since have conflict populating form if updating.

in controller update function add condition like:

if ($this->input->server('request_method') === 'post') {     $this->_get_userinfo_form_fields(); } else {     $this->_get_userinfo_form_fields($user_data); //$user_data database } 

for add function can directly call - $this->_get_userinfo_form_fields();

then declare function below:

protected function _get_userinfo_form_fields($user_data = array()) {     $this->data['rank'] = array(         'placeholder' => 'rank',         'name'        => 'rank',         'id'          => 'rank',         'class'       => '',         'value'       => isset($user_data['rank']) ? $user_data['rank'] :set_value('rank',$this->input->post('rank',true)),         'style'       => '',     );      //add rest of fields here above 1 } 

in view file add code like:

 <?php echo form_input($rank);?> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -