Welcome Guest, Not a member yet? Register   Sign In
custom validations functions
#1

[eluser]Zandy[/eluser]
Hi codeigniters..


In a function of personal validation, as I spend more than one parameter ..
Ex:
Code:
<?php

class Form extends Controller {
    
    function index()
    {
        $this->load->helper(array('form', 'url'));
        
        $this->load->library('validation');
            
        $rules['username']    = "callback_username_check";
        $rules['password']    = "required";
        $rules['passconf']    = "required";
        $rules['email']        = "required";
        
        $this->validation->set_rules($rules);
            
        if ($this->validation->run() == FALSE)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
    
    function username_check($str, $otherParameter)
    {
        if ($str == 'test')
        {
            $this->validation->set_message('username_check', 'The %s field can not be the word "test"');
            return FALSE;
        }
        else
        {
            return TRUE;
        }
    }
    
}
?>

look at $otherParameter in a function

Greetings
#2

[eluser]Colin Williams[/eluser]
Okay. You aren't even using $otherParameter in your username_check() callback. If you need to compare the passed $str with other POSTed values, just capture them with $this->input->post()
#3

[eluser]Zandy[/eluser]
Thank collin...
it worked perfect. :-)




Theme © iAndrew 2016 - Forum software by © MyBB