我们正在使用Gravity Forms,需要阻止用户在提交后再次访问该表单。这是我们在' application.php'中使用的代码。模板:
<?php
if (get_current_user_id()) {
//lookup current application:
$query = "SELECT * FROM dg_application where user_id = " . get_current_user_id();
$dg_application = $wpdb->get_row( $query, ARRAY_A );
if ($dg_application["user_id"] && $dg_application["status"] == "Completed") {
// custom field
echo get_post_meta($post->ID, "form_complete_message", true);
} else {
//let Gravity Forms/WP do thier jobs
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
// End of the loop.
endwhile;
}
} else {
echo "Sorry. You must be logged in to view this form.";
}
?>
</main><!-- .site-main -->
<?php get_sidebar( 'content-bottom' ); ?>
但是它没有工作,也没有像它应该那样显示消息。数据库名称是正确的。我们正在使用自定义数据库。任何想法为什么它可能没有显示?
答案 0 :(得分:0)
我尝试了很多方法。不确定这是否更好,但对我来说效果很好。 如果当前用户已经填写了表单,此代码将阻止他们访问表单。
add_filter( 'gform_get_form_filter_3', 'custom_schedule', 10, 2 );
function custom_schedule( $form_string, $form ) {
$current_user = wp_get_current_user();
$search_criteria = array(
'status' => 'active',
'field_filters' => array( //which fields to search
array(
'key' => 'created_by', 'value' => $current_user->ID, //Current logged in user
)
)
);
$form_id = 3;
$entry = GFAPI::get_entries($form_id,$search_criteria);
if ( !empty($entry) ) {
$form_string = '<p>Sorry, you have reached the submission limit for this form.</p>';
}
return $form_string;
}