Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Invalid rule while validating date
  • Hi,

    I'm trying to use Validation class as it's explained here:


    I've a simple form with a date field I'm using to filter some data, like that:

    <form name="filterByDate" method="post">
    <input type="text" class="date" name="day"/>
    <input class="btn btn-success btn-small" type="submit" name="sbtFilter" value="Filtrer"  />
    </form>

    In order to validate this form, I'm using Validation class as follows:

                $val = \Fuel\Core\Validation::forge('date_filter_validation');

                $val->add('day', 'jour')->add_rule('required')->add_rule('valid_date');
                
                if($val->run()){
                    echo "OK<br />";
                }else{
                    echo "KO<br />";
                }

    But it doesn't work. I'm getting:

    "Notice: Invalid rule "valid_date" passed to Validation, not used. in COREPATH/classes/validation.php [471]: _find_rule"

    If I remove '->add_rule('valid_date')', validation works. But I can't see what I'm doing wrong.

    I hope you can help me.

    Thanks in advance
  • First a remark: do not reference Fuel\Core directly, but use \Validation::forge(). It doesn't cause your issue, but it may cause extension and class reference issues.

    the valid_date rule is defined in the Validation class itself, so it is very odd that it can't be found. What version of FuelPHP are you using? I just pasted your code in a test controller, and it runs find without issues...

  • Hi, Harro. 

    Thanks for the answer. Firstly, I already changed '\Validation::forge()'.

    I'm using 

    /**
    * @var  string  The version of Fuel
    */
    const VERSION = '1.5-dev';

    By the way, there's something I didn't tell you: I'm using netbeans 7.3 with the fuelphp plugin.
    This plugin, I mean:


    Maybe is that the problem?

    Thanks again,
  • I don't know netbeans, but I know you need to use some tricks to make netbeans aware of the existense of the aliased classes.

    For phpstorm I use a dummy classes.php file in the root that defines all aliased classes, probably not entirely complete: http://bin.fuelphp.com/snippet/view/fb
  • Hi filemonpi,

    If you have created a new project from existing source, Please run the following:

    Right-click your project node > FuelPHP > create auto completion file

    And the file for code completion is created to your nbproject directory.

    Thanks.

Howdy, Stranger!

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

In this Discussion