重力表单动态确认不适用于会话变量

时间:2020-04-22 23:00:03

标签: php gravity-forms-plugin gravityforms

提交表单后,我对照值数组检查表单字段的值。如果匹配,我设置会话变量。

session_start();

add_action( 'gform_after_submission', 'validate_the_field', 10, 2 );
function validate_the_field( $entry, $form ) {

    $the_field= $entry["1"];
    if($the_field) {

        $all_fields = explode( ',', get_field('all_fields', 'options') );
        if ( in_array($the_field, $all_fields) ) {
            $_SESSION['authorized'] = 'authorized';
        }

    }
}

我试图根据会话变量显示动态确认消息,但结果始终是“您无权”。

add_filter( 'gform_confirmation', 'custom_confirmation', 10, 4 );
function custom_confirmation( $confirmation, $form, $entry, $ajax ) {

    if ( $_SESSION['authorized'] == 'authorized' ) {
        $confirmation = "You are authorized.";
    } else {
        $confirmation = "You are not authorized.";
    }
    return $confirmation;
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

gform_after_submission过滤器之后 触发gform_confirmation操作。尝试将其替换为gform_entry_created操作,该操作会在确认过滤器之前触发。

有关Gravity Forms挂钩触发顺序的更多详细信息,请参见Gravity Forms Hook参考:

https://gravitywiz.com/gravity-forms-hook-reference/

相关问题