提交表单后,我对照值数组检查表单字段的值。如果匹配,我设置会话变量。
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;
}
感谢您的帮助。
答案 0 :(得分:0)
在gform_after_submission
过滤器之后 触发gform_confirmation
操作。尝试将其替换为gform_entry_created
操作,该操作会在确认过滤器之前触发。
有关Gravity Forms挂钩触发顺序的更多详细信息,请参见Gravity Forms Hook参考: