重力形式动态确认不适用于会话变量
Gravity Forms dynamic Confirmation not working with Session Variables
提交表单后,我根据值数组检查表单字段的值。如果匹配,我设置会话变量。
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';
}
}
}
我正在尝试显示基于会话变量的动态确认消息,但结果始终是 "You are not 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;
}
感谢任何帮助。
gform_after_submission
操作在 gform_confirmation
过滤器之后触发。尝试将其替换为在确认过滤器之前触发的 gform_entry_created
操作。
有关触发 Gravity Forms 挂钩顺序的更多详细信息,请参阅 Gravity Forms Hook 参考:
提交表单后,我根据值数组检查表单字段的值。如果匹配,我设置会话变量。
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';
}
}
}
我正在尝试显示基于会话变量的动态确认消息,但结果始终是 "You are not 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;
}
感谢任何帮助。
gform_after_submission
操作在 gform_confirmation
过滤器之后触发。尝试将其替换为在确认过滤器之前触发的 gform_entry_created
操作。
有关触发 Gravity Forms 挂钩顺序的更多详细信息,请参阅 Gravity Forms Hook 参考: