[eluser]Unknown[/eluser]
Hi,
I have an "edit" page for a form and am using the validation class, but can't figure out how to display the initial value retrieved from the database. If I have to assign the value of the validation to the input, what's a good way to pre-populate the field with the initial value?
view:
Code:
echo form_input('name', $this->validation->name);
controller:
Code:
public function edit() {
$this->load->model('Company_model');
$this->load->library('validation');
$vrules['id'] = 'required';
$vrules['name'] = 'trim|required';
$this->validation->set_rules($vrules);
$vfields['id'] = 'ID';
$vfields['name'] = 'Name';
$this->validation->set_fields($vfields);
if($this->validation->run()) {
// update db and do stuff
} else {
$id = $this->uri->segment(3);
$data['query'] = $this->Company_model->get_single($id);
// display form
$this->load->view('header', $data);
$this->load->view('company/edit');
$this->load->view('footer');
}
}