我用CF7创建了一个表单,然后插入了两个日期字段(带有CF7 datepicker插件) . 这两个字段是[date * date-641 date-format:mm / dd / yy],[date * date-820 date-format:mm / dd / yy] . 表格是预订表格,所以我必须对日期进行一些控制 . date-641是“CHECKIN”日期和日期-820是“CHECKOUT”

我创造了这个:

add_filter('wpcf7_validate_date*','custom_date_confirmation_validation_filter', 10, 2 );

function custom_date_confirmation_validation_filter( $result, $tag ) {

$tag = new WPCF7_Shortcode( $tag );
$date1 = $_POST['date-641'];
$date2 = $_POST['date-820'];
$error_msg = 'Invalid date';
if ($date2 < $date1){
$result->invalidate( 'date-820', $error_msg); //I used $tag instead of 'date-820' with the same results

 }

 return $result;  
}

控件工作正常,但我收到的错误消息不是我在$ error_msg中设置的错误消息,它是通用的“一个或多个字段有错误 . 请检查并重试 . ”我究竟做错了什么?