【问题标题】:Gravity Forms - Prevent Multiple Form Entries Same User ID重力表单 - 防止多个表单条目相同的用户 ID
【发布时间】:2018-07-14 06:12:10
【问题描述】:

我们正在使用重力表单,需要防止用户在提交后再次访问表单。这是我们在“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' ); ?>

但它无法正常工作并且没有按应有的方式显示消息。数据库名称正确。我们正在使用自定义数据库。任何想法为什么它可能没有显示?

【问题讨论】:

  • 对您的代码没有帮助,但如果您只是在寻找解决方案,我有一个插件可以提供帮助:gravitywiz.com/documentation/gravity-forms-limit-submissions
  • 谢谢大卫!我们实际上已经有了那个插件......让我看看它是否可以工作。
  • 确保您已安装 GF 2.3:gravityforms.com/my-account/downloads
  • 嗨,大卫。已安装,启用,但无法正常工作。我们使用的是 GF 2.2.5,但我不认为这是插件的要求。可能是因为我们使用的是自定义表格吗?
  • 你肯定需要 GF 2.3。我会从那里开始,如果您仍有问题,请联系支持人员:gravitywiz.com/support

标签: php gravity-forms-plugin gravityforms


【解决方案1】:

我尝试了很多方法。不确定这是否是更好的方法,但它对我来说效果很好。 如果当前用户已经填写了表单,此代码将阻止他们访问表单。

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;
}

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 2016-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    相关资源
    最近更新 更多