[eluser]minerbog[/eluser]
Hi Guys,
Now I'm not sure if im barking up the wrong tree here, but I am trying to do a little as possible (as normal
) but have ended up spending ages trying to work this out!
I have a view file I want to use for inputing and editing data.
Code:
<?php echo validation_errors(); ?>
<h2>Employee stuff updated to old record</h2>
Employeeid:<input type="text" name="employeeid" value="<?php echo set_value('employeeid'); ?>" /><br />
Surname:<input type="text" name="surname" value="<?php echo set_value('surname'); ?>" /><br />
Title:<input type="text" name="title" value="<?php echo set_value('title'); ?>" /><br />
Initials:<input type="text" name="initials" value="<?php echo set_value('initials'); ?>" /><br />
Firstname:<input type="text" name="firstname" value="<?php echo set_value('firstname'); ?>" /><br />
Address1:<input type="text" name="address1" value="<?php echo set_value('address1'); ?>" /><br />
Address2:<input type="text" name="address2" value="<?php echo set_value('address2'); ?>" /><br />
Address3:<input type="text" name="address3" value="<?php echo set_value('addrress3'); ?>" /><br />
Postcode:<input type="text" name="postcode" value="<?php echo set_value('postcode'); ?>" /><br />
<input type="submit" /><br />
</form>
This works fine for adding and validating new records. However, I assumed that because the set_value function uses the $_POST variable I could do this:
Code:
public function edit($id)
{
//function to edit employees
$this->load->library('form_validation');
$this->_set_rules();
if ($this->form_validation->run() == FALSE)
{
$query = $this->employees_m->get_one_employee($id);
if ($query->num_rows() == 1)
{
$new = $query->result_array();
}
//Set array to POST array for processing
$_POST = $new[0];
$old = array_shift($_POST);
$this->load->helper('form');
$this->load->view('employees_add');
} else {
$data = $this->input->post(NULL, TRUE);
//set not inputed data
$this->employees_m->update('employee_data', $data);
echo 'Success';
}
}
The $_POST array displays ok on the view page with print_r but set_value doesn't seem to use it and returns blank fields.
Have I done something obviously wrong or just an idiot for trying something it cannot do!!
Regards,
Gav.