wordpress 插件 GravityForms differenciate limit submissions for the same module in different pages

wordpress plugin GravityForms differenciate limit submissions for the same module in different pages

我正在尝试找出一种方法来区分不同页面上“共享”表单的提交限制。

如果我在一个表单(在不同页面上共享)中激活内置功能“限制提交”,那么提交限制也会共享。 我试着解释得更好

我需要能够根据使用表单的特定页面来限制提交,因此在这种特定情况下,我需要能够在第 1 页上保留 40 个提交,但在其他两个页面上仍然保留 50 个提交页数。

你对我如何实现这一点有什么建议吗? 谢谢

我不知道用代码完成此操作的简单方法,但我有一个插件可以处理每页的提交限制。

https://gravitywiz.com/documentation/gravity-forms-limit-submissions/#embed-url

Embed URL

Limit by the URL from which the entry was submitted. This is very useful when using the same form on multiple pages and wanting to apply the Feed Limit per page rather than per form.

您可以尝试添加一个隐藏字段来捕获默认值中包含以下合并标签的嵌入页面:{embed_url}

然后将此添加到您的 functions.php

add_filter( 'gform_get_form_filter_100', 'limit_by_embed_page', 10, 2 );//replace 100 with your form id
function limit_by_embed_page( $form_string, $form ) {
    $page=array("page1","page2","page3");//replace with name of pages where form is embedded
    for($x=0;$x<count($page);$x++){
        $search_criteria[$x] = array(
            'status'        => 'active',
            'field_filters' => array(
                'mode' => 'all',
                array(
                    'key'      => '2',
                    'operator' => 'contains',
                    'value'    => $page[$x]
                )
            )
        );
            
        $entries[$x] = GFAPI::get_entries($form,$search_criteria[$x]);
        $entries_count[$x] = count($entries[$x]);
        if ( $entries_count[$x] > 50 && strpos($_SERVER['REQUEST_URI'], $page[$x]) !== false) {//change 50 to the # of the page limit
            $form_string = '<p>Sorry, the submission limit for this  has been reached.</p>';
        }
    }   
    return $form_string;
}