Welcome Guest, Not a member yet? Register   Sign In
Basic Form question - just can't recall how!
#1

Hi,
Got a simple 'edit' style form which, when submitted, gets validated. If there are errors then I want to redisplay the form with whatever the user entered ... can;t for the life of me recal how to do the redisplay!!!

Here's the controller which loads the form:
Code:
public function edit_staff($par_id)
{
$this->data['staff'] = $this->M_staff->get_selected($par_id);
$alldepts=$this->M_department->get_all();
$this->data['dropdown'] = $this->M_department->build_dept_dropdown($alldepts);
$this->data['title'] = 'staff Management';
$this->data['message'] = $this->session->flashdata('message');
$this->data['main'] = 'v_staff_edit';
$this->load->view('v_template', $this->data, 'refresh');
}
Here's the controller that validates it and 'should'  do the redisplay
Code:
public function edit_staff_submit()
{
if ($this->form_validation->run('staff') == true)
{
$data = array(
'fname'=> $this->input->post('fname'),
'lname' => $this->input->post('lname'),
'dept'=> $this->input->post('dept')
);
$this->M_staff->update_record($this->input->post('staffid'),$data);
$this->session->set_flashdata('message', "<p>staff updated successfully.</p>");
redirect('staff/index', 'refresh');
}
else  // If validation fails, r.edisplay
{
What to do here, how do i redisplay view?????
}

}

Here's the view:

Code:
   <div class="row">
       <div class="col-md-6 col-md-offset-3 well">
       <?php
       echo form_open("staff/edit_staff_submit/");
       echo form_hidden('staffid', $staff->staffid);
        ?>
       <fieldset>
           
           <div class="form-group">
<div class="row colbox">
<div class="col-md-4">
<label for="fname" class="control-label">First Name</label>
</div>
<div class="col-md-8">
<input id="fname" name="fname" placeholder="fname" type="text" class="form-control"  value="<?php echo set_value('fname', $staff->fname); ?>" />
<span class="text-danger"><?php echo form_error('fname'); ?></span>
</div>
</div>
           </div>
           <div class="form-group">
<div class="row colbox">
<div class="col-md-4">
<label for="fname" class="control-label">Last Name</label>
</div>
<div class="col-md-8">
<input id="lname" name="lname" placeholder="Last name" type="text" class="form-control"  value="<?php echo set_value('lname', $staff->lname); ?>" />
<span class="text-danger"><?php echo form_error('fname'); ?></span>
</div>
</div>
</div>

           <div class="form-group">
<div class="row colbox">
<div class="col-md-4">
<label for="Department" class="control-label">Department</label>
</div>
<div class="col-md-8">
<?php echo form_dropdown('dept', $dropdown, $staff->dept);?>
<span class="text-danger"><?php echo form_error('fname'); ?></span>
</div>
</div>
</div>


</div>
</div>          

           <div class="form-group">
           <div class="col-sm-offset-4 col-md-8 text-left">
               <input id="btn_update" name="btn_update" type="submit" class="btn btn-primary" value="Update" />
               <?php echo anchor('staff/index','<input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-danger" value="Cancel">')?>
           </div>
           </div>
       </fieldset>
       <?php echo form_close(); ?>
       <?php echo $this->session->flashdata('msg'); ?>
       </div>
   </div>
Reply


Messages In This Thread
Basic Form question - just can't recall how! - by blackbulldog - 02-17-2015, 11:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB