我在 WordPress 上的 Functions.php 文件中设置了此过滤器,用于验证日期,因此取货日期时间早于返回日期和时间。当日期和时间输入正确时,它应该通过验证,但它一直失败,我只是无法理解这一点。它突然停止工作了。我只能查明这一点以将服务器上的日期/时间设置为格林威治时间。
add_filter( 'gform_validation', 'custom_validation' );
function custom_validation( $validation_result ) {
$form = $validation_result['form'];
$pickupDate = null;
$returnDate = null;
foreach( $form['fields'] as & $field ) {
if ( $field->label == 'Pickup Date' ) {
$pickupDate = rgpost('input_' . $field->id);
//var_dump("Pickup Date:" . $pickupDate);
}
if ( $field->label == 'Pickup Time' ) {
$pickupDate .= ' ' . rgpost('input_' . $field->id);
//var_dump("Pickup Time:" . $pickupDate);
}
if ( $field->label == 'Return Date' ) {
$returnDate = rgpost('input_' . $field->id);
//var_dump("Return Date:" . $returnDate);
}
if ( $field->label == 'Return Time' ) {
$returnDate .= ' ' . rgpost('input_' . $field->id);
//var_dump("Return Time:" . $returnDate);
if (strtotime($returnDate) <= strtotime($pickupDate)) {
//var_dump($returnDate);
//var_dump($pickupDate);
$validation_result['is_valid'] = false;
$field->failed_validation = true;
$field->validation_message = 'Please ensure your selected Pickup Date and time is earlier than your Return Date and Time';
break;
}
}
}
//Assign modified $form object back to the validation result
$validation_result['form'] = $form;
return $validation_result;
}
add_filter( 'gform_pre_send_email', function ( $email, $message_format ) {
if ( $message_format != 'html' ) {
return $email;
}
任何人都可以找出问题出在哪里吗?
当您访问此URL时,您需要单击“需要报价”按钮。
慕哥9229398