1 回答
TA贡献1877条经验 获得超6个赞
您只需从验证条件中删除 = 即可。
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;
}
- 1 回答
- 0 关注
- 155 浏览
添加回答
举报