如何在wordpress插件联系人表单7中验证当前服务器时间?
当用户单击“提交”按钮时,我需要验证当前服务器的时间和日期,如果服务器时间不在所需的时间间隔或天数(周末)内,则返回错误消息。解决了这个问题如何在wordpress插件联系人表单7中验证当前服务器时间?,wordpress,contact-form-7,Wordpress,Contact Form 7,当用户单击“提交”按钮时,我需要验证当前服务器的时间和日期,如果服务器时间不在所需的时间间隔或天数(周末)内,则返回错误消息。解决了这个问题 add_action("wpcf7_before_send_mail", "wpcf7_do_something_else", 15, 3); function wpcf7_do_something_else($cf7, &$abort, $submission) { $id = $cf7->id();
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else", 15, 3);
function wpcf7_do_something_else($cf7, &$abort, $submission) {
$id = $cf7->id(); // id of your cf7 form
if ($id == 3580) {
$date = date_i18n( get_option( 'date_format' ) );
$date = explode(" ", $date);
$day = $date[0];
$time = date_i18n( get_option( 'time_format' ) );
$time = explode(':',$time);
$hour = intval($time[0]);
//custom day and time validation
if ( ( $day == 'Sunday' || $day == 'Saturday' ) || !( ( 5 <= $hour) && ($hour <= 20) ) || ( $day == "Friday" && $hour >= 20 ) ) {
$abort = true; // &$abort reference
$submission->set_status( 'validation_failed' );
$errMsg = "Your error message"; // custom error message
$submission->set_response( $cf7->filter_message($errMsg) );
}
}
return $wpcf;
}
add_action(“wpcf7_发送邮件之前”、“wpcf7_做其他事情”,15,3);
函数wpcf7_do_something_other($cf7,&$abort,$submission){
$id=$cf7->id();//您的cf7表单的id
如果($id==3580){
$date=date_i18n(获取选项('date_格式');
$date=分解(“,$date”);
$day=$date[0];
$time=date_i18n(get_选项('time_格式');
$time=explode(“:”,$time);
$hour=intval($time[0]);
//自定义日期和时间验证
如果($day=='Sunday'| |$day=='Saturday')| |!((5设置_状态('validation_failed'));
$errMsg=“您的错误消息”;//自定义错误消息
$submission->set_response($cf7->filter_message($errMsg));
}
}
返回$wpcf;
}
希望这对某人有帮助:)您已经编写了哪些代码?请阅读,然后在问题中包含并标记您的代码。干杯!我决定使用服务器端验证,因为它更简单,而且似乎工作正常。我的代码没有被包括在内的原因是,我不知道从何处开始。我只是想找人向我展示正确的way:)