下面是一些关于如何简单地利用gform_after_submission
重力钩子表单,用于根据提交的表单ID设置cookie,然后在确认页面上通过钩子template_redirect
.
为了自定义功能,您需要查看以下文档:setcookie
, gform_after_submission
和template_redirect
.
For the form
// Make sure to swap out {your_form_id} with the ID of the form.
add_action( \'gform_after_submission_{your_form_id}\', \'wpse_set_submitted_cookie\', 10, 2 );
function wpse_set_submitted_cookie( $entry, $form ) {
// Set a third parameter to specify a cookie expiration time,
// otherwise it will last until the end of the current session.
setcookie( \'wpse_form_submitted\', \'true\' );
}
For the page add_action( \'template_redirect\', \'wpse_protect_confirmation_page\' );
function wpse_protect_confirmation_page() {
if( is_page( \'my-confirmation-page\' ) && ! isset( $_COOKIE[\'wpse_form_submitted\'] ) ) {
wp_redirect( home_url( \'/my-form/\' ) );
exit();
}
}