为了账号安全,请及时绑定邮箱和手机立即绑定

重力形式:日期验证失败

重力形式:日期验证失败

PHP
回首忆惘然 2023-06-24 18:35:14
我在 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时,您需要单击&ldquo;需要报价&rdquo;按钮。
查看完整描述

1 回答

?
慕哥9229398

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 反对 回复 2023-06-24
  • 1 回答
  • 0 关注
  • 155 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信