[eluser]Bramme[/eluser]
Hey all,
I've run into a spot of trouble using validation.
Code:
$data['form'] = array(
'name' => array(
'name' => 'name',
'id' => 'name',
'value' => $this->validation->name
),
'password' => array(
'name' => 'password',
'id' => 'password'
),
'email' => array(
'name' => 'email',
'id' => 'email',
'value' => $this->validation->email
),
'message' => array(
'name' => 'message',
'id' => 'message',
'value' => $this->validation->message
),
'submit' => array(
'name' => 'submComment',
'value' => 'Submit'
)
);
if($this->validation->run() != false) {
//remove values
$form = array(
'name' => array(
'value' => ''
),
'email' => array(
'value' => ''
),
'message' => array(
'value' => ''
),
);
// $data['form'] = array_merge($data['form'], $form);
//validation passed, add the comment
$insert['newsID'] = $this->input->post('newsID');
$insert['is_registered'] = $this->input->post('password') != false ? 1 : 0;
$insert['time'] = time();
$insert['name'] = $this->input->post('name');
$insert['email'] = $this->input->post('email');
$insert['message'] = $this->input->post('message');
$this->db->insert('comments', $insert);
}
This works perfectly fine. However, when I uncomment $data['form'] = array_merge($data['form'], $form); validation fails and throws errors against all the rules I set.
I'm merging those two arrays so the values from my form disappear, seeing as I don't show a succes view (like suggested in the user guide) but simply the same form again...