Welcome Guest, Not a member yet? Register   Sign In
I'm happy, the best edit form i've created
#1

[eluser]cPage[/eluser]
Inside Controller
Code:
public function edit($id)
{
  $this->data = array('header' => array('title' => $this->lang->line('factures_edit_title')),
            'nav' => array('active'=>'factures_edit'),
            'content' => array('facture' => $this->facture_model->get_facture($id),
                      'fields' => $this->facture_model->select_fields(),
                      'form_error' => $this->form_error,
                      'list_client'=> $this->client_model->select_list('id_client,client')));
                      
  $this->template->set('header', $this->config->item('theme_url').'header', $this->data['header'])
          ->set('nav', $this->config->item('theme_url').'user/nav', $this->data['nav'])
          ->set('content', $this->config->item('theme_url').'facture/edit', $this->data['content'])
          ->load($this->config->item('theme_url').'m_template');
}
Code:
public function update()
{
  $this->validation();
  
  if ($this->form_validation->run() == FALSE)
  {
   $this->form_error = TRUE;
   $this->edit($this->input->post('id_facture'));
  }
  else
  {
   $id_facture = $this->input->post('id_facture');
   $this->facture_model->update($this->input->post(),array('id_facture' => $id_facture));
   $this->common->set_message('alert alert-success',sprintf($this->lang->line('factures_edit_message'),$this->input->post('facture')));
   $this->index();
  }
}
The view
Code:
<div class="page-header">
  <h3>&lt;?=$this->lang->line($active.'_title')?&gt;</h2>
</div>
<div class="container">
&lt;form class="form-horizontal" method="post" acti&gt;
&lt;?php
foreach($fields as $field)
{
  $data = array('label'=>ucfirst($this->lang->line($field)),
         'name'=>$field,
         'help'=>$this->lang->line($active.'_'.$field.'_help'),
         'success'=>$this->lang->line($active.'_'.$field.'_valid'));    
  
  switch($field)
  {    
   case 'id_facture':
    $data['type'] = 'hidden';
   break;
  
   case 'client_id':
    $temp = array('type'=>'dropdown',
           'list'=>$list_client,
           'primary'=>'id_client',
           'fieldlist'=>'client');
    $data = array_merge($data,$temp);
   break;
  }
  
  echo ($form_error)?form_input_controls($data,set_value($field)):form_input_controls($data,$facture->$field);
}
?&gt;
<div class="control-group">
  <div class="controls">
   <button type="submit" class="btn">&lt;?=$this->lang->line('edit_submit')?&gt;</button>
  </div>
</div>
&lt;/form&gt;
</div>




Theme © iAndrew 2016 - Forum software by © MyBB