Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
mulitple validation group
  • Hi Guys! I can't get the following code to work. The first validation group works not the other two.
            $cust = \Validation::factory("customer");
            $cust->add_field('title', 'Title', 'required');
            $cust->add_field('firstname', 'Firstname', 'required');
            $cust->add_field('lastname', 'Lastname', 'required');
    
            $ben = \Validation::factory("ben");
            $ben->add_field('ben_title', 'Title', 'required');
            $ben->add_field('ben_name', 'Name', 'required');
    
            $pay = \Validation::factory("pay");
            $pay->add_field('payment_method_id', 'Payment method', 'required');
            $pay->add_field('payment_account_no', 'Account', 'required');
    
        if (\Input::method() == 'POST'  && $cust->run() && $pay->run() && $ben->run()) {
    
        }
    
                \Session::set_flash('validation', $cust->show_errors());
                \Session::set_flash('ben', $ben->show_errors());
                \Session::set_flash('pay', $pay->show_errors());
    
    

    $cust->show_errors() works fine but $ben->show_errors() & $pay->show_errors() doesn't show any errors. What am i doing wrong? thanks.
  • got it working, logical operator was wrong ... if (\Input::method() == 'POST' && $cust->run() || $pay->run() || $ben->run()) {
  • Sorry, it's not working. Now i'm getting error messages for all 3 validations but $pay->validated does not contain value.
  • I don't think you fully understand how boolean operators work: - AND: the right hand side is ONLY executed when the lefthand side is true. When the first condition validates to false the second condition is never executed.
    - OR: the right hand side is ONLY executed when the lefthand side is false. When the first condition validates to true the second condition is never executed. Both of this is a very logical compiler optimization that is true in all programming languages as far as I know. The reasoning is simple: for AND the whole statement can only be true if both are true, if the first one is false the whole can never be true and the second arguement can be ignored. For OR if the first arguement is true the whole statement is already true, no reason to check the second.

Howdy, Stranger!

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

In this Discussion