Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to Add validation valid_date
  • Hi

    I am little bit confuse for add validation valid_date, this is what I am try for achieve that.

    $val->add('start_date', 'Start Date')
                    ->add_rule('trim')
                    ->add_rule('valid_date','mm/dd/yyyy')
                    ->add_rule('max_length', 10);

    when I am try to submit with false case that not show error , maybe something gone wrong on rule vali_date , I am use fuelphp 1.6+, can someone give me the truth of validation valid_date ?

    Note : 
    I have solve by my self I am wrong format this is the true

    $val->add('start_date', 'Start Date')
                    ->add_rule('trim')
                    ->add_rule('required')
                    ->add_rule('valid_date','Y-m-d')
                    ->add_rule('max_length', 10);
  • HarroHarro
    Accepted Answer
    valid_date uses "date_parse_from_format", see http://php.net/manual/en/function.date-parse-from-format.php.

    This will lead you to http://php.net/manual/en/datetime.createfromformat.php, which will tell you the format string should be "m/d/Y".

    You can test this using the oil console:

    Fuel 1.8-dev - PHP 5.5.15 (cli) (Jul 24 2014 12:52:12) [Linux]
    >>> var_dump(date_parse_from_format('m/d/Y', '12/24/2014'));
    array(12) {
      'year' =>  int(2014)
      'month' =>  int(12)
      'day' =>  int(24)
      'hour' =>  bool(false)
      'minute' =>  bool(false)
      'second' =>  bool(false)
      'fraction' =>  bool(false)
      'warning_count' =>  int(0)
      'warnings' =>  array(0) {
      }
      'error_count' =>  int(0)
      'errors' =>  array(0) {
      }
      'is_localtime' =>  bool(false)
    }
    >>>

    Using the oil console you can run any Fuel command or access any Fuel class, which can be handy for all sorts of debugging operations:

    Fuel 1.8-dev - PHP 5.5.15 (cli) (Jul 24 2014 12:52:12) [Linux]
    >>> $val = \Validation::forge();
    >>> var_dump($val->_validation_valid_date('12/24/2014', 'm/d/Y'));
    string(10) "12/24/2014"
    >>> var_dump($val->_validation_valid_date('1/24/2014', 'm/d/Y'))
    string(10) "01/24/2014"
    >>> var_dump($val->_validation_valid_date('24/24/2014', 'm/d/Y'))
    bool(false)
    >>>

  • this great , actually I want to ask again about oil task , but you answer in this too.

Howdy, Stranger!

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

In this Discussion