Reputation: 731
I have one form for the edit and create for a user. On the form I have an if statement that if the form is an edit then it places a hidden form element that holds the value of the user being updated.
When I value the form on the php side controller this is what I'm using to do it with.
$user_id = $this->input->post('user_id');
if (isset($user_id_id))
{
$this->form_validation->set_rules('user_id', 'User ID', 'required|trim|xss_clean|integer');
}
I have not tested this on the edit form but on the add form it is saying that the user id is requred and I'm not sure why.
Upvotes: 0
Views: 63
Reputation: 146219
You can simply use
if($this->input->post('user_id'))
{
$this->form_validation->set_rules('user_id', 'User ID', 'required|trim|xss_clean|integer');
}
Upvotes: 1
Reputation: 42450
In CodeIgniter, $this->input->post('foobar')
returns the value of $_POST['foobar']
if it exists, or a false
if it doesn't. Either ways, a value is set, and so isset()
will evaluate to a true.
Use if ($user_id !== FALSE)
instead.
Upvotes: 2