Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Custom validation
  • Hi Guys! I'm creating custom validation my extending the validation class, I like to know how do I pass multiple input the the custom validation?
    class Myvalidation {
    
        public function _validation_dob($d, $m, $y) {
            if ($d == "0" && $m == "0" && $y == "0")
                return false;
        }
    
    }
    

    Basically I have 3 dropdownlists for the user to pick their date of birth.. i like to send one error message instead of 3. I tried this but didn't work.
     $val->add_field('day', 'Your date of birth', 'dob[d,m,y]');
    
  • Currently the only rule that does something similar is within the Validation class: match_field That works because it can get the Validation instance to ask for the input. However, if you will only use this with POSTed values and never with manual input you could just check Input::post() for all three values:
    public function _validation_dob()
    {
        if (Input::post('day') == "0" && Input::post('month') == "0" && Input::post('year') == "0")
            return false;
    }
    

    Or if you only use 1 unnamed Validation instance:
    public function _validation_dob()
    {
        $val = Validation::instance();
        if ($val->input('day') == "0" && $val->input('month') == "0" && $val->input('year') == "0")
            return false;
    }
    

    Otherwise, if you need to check the other values from the form input you'll have to extend the validation class to be able to use $this->input(). I'll think about making that available in another way outside the class, the problem is that if you use multiple validation instances there's no way for you method to figure out which instance to ask the given input from.
  • Jelmer Schreuder wrote on Monday 18th of April 2011:
    Currently the only rule that does something similar is within the Validation class: match_field That works because it can get the Validation instance to ask for the input. However, if you will only use this with POSTed values and never with manual input you could just check Input::post() for all three values:
    public function _validation_dob()
    {
        if (Input::post('day') == "0" && Input::post('month') == "0" && Input::post('year') == "0")
            return false;
    }
    

    Or if you only use 1 unnamed Validation instance:
    public function _validation_dob()
    {
        $val = Validation::instance();
        if ($val->input('day') == "0" && $val->input('month') == "0" && $val->input('year') == "0")
            return false;
    }
    

    Otherwise, if you need to check the other values from the form input you'll have to extend the validation class to be able to use $this->input(). I'll think about making that available in another way outside the class, the problem is that if you use multiple validation instances there's no way for you method to figure out which instance to ask the given input from.

    Thanks for that, didn't think the post variables was available within the validation class. Thanks again for being very helpful as always :)
  • Huzzi, No disrespect but why do you quote the previous posts every time you reply because I have to scroll through stuff that I have already read and it makes the page really long especially when viewing from a phone. Just a note ;-) Phil.
  • no worries... i think the reply button should be next to the Quote... that will stop me hitting the quote button :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion