Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
What's wrong with this validation object?
  • $val = Validation::forge('my_validation');
                $val->add('search_target', 'search_target')->add_rule('required');
                $val->add('tmtrip_id', 'tmtrip_id')->add_rule('required|valid_string[numeric]');

    The program says the last rule is invalid... But in the documentation (validation class), valid_string is mentioned as as a rule, and  'numeric' is mentioned as a array parameter for valid_string...
     Am I using it the wrong way?


  • HarroHarro
    Accepted Answer
    You're using incorrect syntax.

    As the example (http://docs.fuelphp.com/classes/validation/validation.html#rules) shows, there are two ways to define rules for a field:

    using add_field(), in which you define all rules in a single string (the syntax you used), or
    add_rule(), which is used to define a  single rule

    Since you're using the last one, it should be

    $val->add('tmtrip_id', 'tmtrip_id')
        ->add_rule('required')
        ->add_tule('valid_string', array('numeric'));

  • Thank you very much

Howdy, Stranger!

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

In this Discussion