Welcome Guest, Not a member yet? Register   Sign In
validation : return formatted rule fields
#1

[eluser]xwero[/eluser]
I don't know if it's possible so i want to ask it first.

The idea behind it is simple. You have all those rules to validate the input and when the validation succeeds you can use the rules instead of doing the same thing over again with the post variables.

In code this would be something like this

Code:
$this->load->library('validation');
        
$rules['username'] = "trim|required|min_length[5]|max_length[12]|xss_clean";
$rules['password'] = "trim|required|matches[passconf]|md5";
$rules['passconf'] = "trim|required";
$rules['email'] = "trim|required|valid_email";
    
$this->validation->set_rules($rules);
    
$fields['username']    = 'Username';
$fields['password']    = 'Password';
$fields['passconf']    = 'Password Confirmation';
$fields['email']    = 'Email Address';

$this->validation->set_fields($fields);
        
if ($this->validation->run() == FALSE)
{
    $this->load->view('myform');
}
else
{
    $this->model->add($this->validation->username,$this->validation->password,$this->validation->passconf,$this->validation->email);
    $this->load->view('formsuccess');
}

I tested this example but the $this->validation->username returned the post variable.
#2

[eluser]alpar[/eluser]
if you didn't put any leading trailing spaces, or anything that gets cut out in the XSS filter that you get the post variable as is, and yo get a false on the run() method if it doesn't match the rules. If i missed your point please let me know Smile
#3

[eluser]BravoAlpha[/eluser]
[quote author="xwero" date="1187875680"]when the validation succeeds you can use the rules instead of doing the same thing over again with the post variables.[/quote]
The post variables are modified directly.

Edit: Wait, `$this->validation->whatever` should (from what I see) have the same changes applied to it as the $_POST[] variable. Are you saying that it doesn't work for you?




Theme © iAndrew 2016 - Forum software by © MyBB