Welcome Guest, Not a member yet? Register   Sign In
Form helper Set_value function
#1

[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 Smile) 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:&lt;input type="text" name="employeeid" value="&lt;?php echo set_value('employeeid'); ?&gt;" /&gt;&lt;br />
Surname:&lt;input type="text" name="surname" value="&lt;?php echo set_value('surname'); ?&gt;" /&gt;&lt;br />
Title:&lt;input type="text" name="title" value="&lt;?php echo set_value('title'); ?&gt;" /&gt;&lt;br />
Initials:&lt;input type="text" name="initials" value="&lt;?php echo set_value('initials'); ?&gt;" /&gt;&lt;br />
Firstname:&lt;input type="text" name="firstname" value="&lt;?php echo set_value('firstname'); ?&gt;" /&gt;&lt;br />
Address1:&lt;input type="text" name="address1" value="&lt;?php echo set_value('address1'); ?&gt;" /&gt;&lt;br />
Address2:&lt;input type="text" name="address2" value="&lt;?php echo set_value('address2'); ?&gt;" /&gt;&lt;br />
Address3:&lt;input type="text" name="address3" value="&lt;?php echo set_value('addrress3'); ?&gt;" /&gt;&lt;br />
Postcode:&lt;input type="text" name="postcode" value="&lt;?php echo set_value('postcode'); ?&gt;" /&gt;&lt;br />
&lt;input type="submit" /&gt;&lt;br />
&lt;/form&gt;

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.


Messages In This Thread
Form helper Set_value function - by El Forum - 07-31-2012, 05:19 AM
Form helper Set_value function - by El Forum - 07-31-2012, 02:03 PM
Form helper Set_value function - by El Forum - 08-01-2012, 01:58 AM
Form helper Set_value function - by El Forum - 08-01-2012, 03:27 AM
Form helper Set_value function - by El Forum - 08-01-2012, 03:43 AM
Form helper Set_value function - by El Forum - 08-01-2012, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB