Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    I guess I can do a validation filter, but a date picker would be much cooler.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    It seems that this validation never gets fired… The field name sure looks correct. Am I getting it right?

    The form is validated whether the field value is ‘abc’ or ‘1/1/2015’

    add_filter( 'sfwp2l_validate_field', 'fs_salesforce_validate_date' );
    
    function fs_salesforce_validate_date( $error, $name, $val, $field) {
             if ( '00N60000001J7la' == $name ) {
                $t = strtotime ( $val );
                if ( !$t) {
                     $error['valid'] = false;
                     $error['message'] = 'Please enter a date as m/d/yyyy';
                     }
                 }
             return $error;
    }

    the field’s HTML is
    <input placeholder="" value="" id="sf_00N60000001J7la" class="w2linput text" name="00N60000001J7la" type="text">

    Plugin Author Nick Ciske

    (@nickciske)

    strtotime will always return a date, it just returns the Unix epoch for invalid dates.

    I think you need to add checkdate() to your conditional.

    http://php.net/manual/en/function.checkdate.php

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    my testing shows strtotime returns false if the date is invalid, per the php.net docs, but I’ll try checkdate. Thanks.

    Plugin Author Nick Ciske

    (@nickciske)

    I’ve never seen strtotime return false… but I’m not sure what input you’re testing it on.

    Plugin Author Nick Ciske

    (@nickciske)

    You forgot to indicate you want more than 1 variable passed, so $name could be blank.

    add_filter( 'sfwp2l_validate_field', 'fs_salesforce_validate_date', 10, 4 );

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Thank you. That was it. Need the 10,4.

    10-4!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Datepicker’ is closed to new replies.