I guess I can do a validation filter, but a date picker would be much cooler.
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">
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
my testing shows strtotime returns false if the date is invalid, per the php.net docs, but I’ll try checkdate. Thanks.
I’ve never seen strtotime return false… but I’m not sure what input you’re testing it on.
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 );
Thank you. That was it. Need the 10,4.
10-4!