Welcome Guest, Not a member yet? Register   Sign In
Odd validation problem
#1

[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...
#2

[eluser]Bramme[/eluser]
Nobody got a clue?
#3

[eluser]xwero[/eluser]
give this solution a try.
#4

[eluser]Bramme[/eluser]
Thanks, this throws an error though:
Fatal error: Call to undefined method MY_Validation::_rules() in /var/www/vhosts/bramme.net/subdomains/mickm/httpdocs/systeem/applicatie/libraries/MY_Validation.php on line 5


edit: had to remove the ()... It's just _rules. But it doesn't work.


edit2: it does work. I forgot I put the array with form attributes above the clear_values function, and I had to put it below.

Thanks xwero!




Theme © iAndrew 2016 - Forum software by © MyBB