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

[eluser]Krzemo[/eluser]
Hi,

I'm currently working on user registration and tried to learn how to use validation.
Everything is ok except... my form is not being validated. Method run() always returns 1.
Am I missing something here? Fields names are ok (first param of set_rules())...

Below is method I call on form submit.

Thnx for taking a look.

Code:
function registeruser() {
        $validation_status = null;
        
        $this->load->library('validation');

        $this->lang->load('register');

        $this->validation->set_rules('login', 'lang:register_validation_login', 'trim|required|xss_clean');
        $this->validation->set_rules('password1', 'lang:register_validation_password1', 'trim|required|matches[password2]|min_length[6]|max_length[45]|md5');
        $this->validation->set_rules('password2', 'lang:register_validation_password2', 'trim|required');
        $this->validation->set_rules('firstname', 'lang:register_validation_firstname', 'trim|required');
        $this->validation->set_rules('lastname', 'lang:register_validation_lastname', 'trim|required');
        $this->validation->set_rules('email', 'lang:register_validation_email', 'trim|required|valid_email');
        $this->validation->set_rules('address_street_name', 'lang:register_validation_address_street_name', 'trim|required');
        $this->validation->set_rules('address_street_number', 'lang:register_validation_address_street_number', 'trim|required');
        $this->validation->set_rules('address_flat', 'lang:register_validation_address_flat', 'trim|required');
        $this->validation->set_rules('address_city', 'lang:register_validation_address_city', 'trim|required');
        $this->validation->set_rules('address_zip', 'lang:register_validation_zip', 'trim|required');
        $this->validation->set_rules('birthdate_years', 'lang:register_validation_birthdate_year', 'required');
        $this->validation->set_rules('birthdate_months', 'lang:register_validation_birthdate_month', 'required');
        $this->validation->set_rules('birthdate_days', 'lang:register_validation_birthdate_day', 'required');
        $this->validation->set_rules('telephone_mobile', 'lang:register_validation_mobiletelephone', 'trim|required');
        $this->validation->set_rules('fk_address_country_id', 'lang:register_validation_country', 'required');
        $this->validation->set_rules('fk_education_id', 'lang:register_validation_education', 'required');
        
        if ($this->validation->run() == FALSE) {
            $data['validation_errors'] = $this->validation->validation_errors();
            $this->load->view('common/vregister');
        } else {
            $this->load->view('common/vregistersuccess');
        }        

    }
#2

[eluser]OES[/eluser]
It should be

Code:
$data['validation_errors'] = validation_errors();

Good luck
#3

[eluser]Krzemo[/eluser]
Im pretty sure this is not the reason why $this->validation->run() is always TRUE...
But thnx
#4

[eluser]lmv4321[/eluser]
The library to load is form_validation in 1.7.0 and not validation (which is 1.6.3).
#5

[eluser]OES[/eluser]
Sorry my bad.

Getting l8 here.

imv4321 is correct you are using new form_validation but loading the old validation library.

Well played.
#6

[eluser]PV-Patrick[/eluser]
Was this ever solved? I am having a similar problem in that NO errors are being returned to me on validation.

Code:
CONTROLLER:

if($this->form_validation->run('add_cp_user') == FALSE) {
    print_r($this->form_validation->_field_data);
    print_r($this->form_validation->_config_rules);
    print_r($this->form_validation->_error_array);
} else {
}

Code:
form_validation.php Config File

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config = array(
        'add_cp_user' =>    array(
                                array(
                                    'field'    => 'username',
                                    'label'    => 'account_username',
                                    'rules'    => 'trim|required|htmlspecialchars|min_length[6]|max_length[50]'
                                ),
                                array(
                                    'field'    => 'password',
                                    'label'    => 'account_password',
                                    'rules'    => 'trim|required|htmlspecialchars|min_length[6]|max_length[30]|matches[confirm_password]'
                                ),
                                array(
                                    'field'    => 'confirm_password',
                                    'label'    => 'account_confirm_password',
                                    'rules'    => 'trim|required|htmlspecialchars|min_length[6]|max_length[30]|matches[password]'
                                )
                            )
);

?>

The only thing that is not empty is the _config_rules array. However, no errors are returned. Anyone have any suggestions?
#7

[eluser]Krzemo[/eluser]
It's working for me finally, but I'm not using config file for validation rules.
Problem on my site was, that I havn't noticed that documentation version changed to 1.7 while I was still usintg 1.6.3.
#8

[eluser]PV-Patrick[/eluser]
I figured it out.... and unfortunately feel like an idiot. I am doing it via ajax callback and wasn't setting the variable I was sending to $_POST so it was not triggering the validation on it. Ugh...




Theme © iAndrew 2016 - Forum software by © MyBB