PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

limited access to a form for a logged in user,

  1. Is there a way to limit the access to a form for a logged in user?

    Example: if the user just posted 3 new. We would like for that user to take a time out. So can the form then be un accessible to that user for a certain period? under "form settings" there is a "limit number of entries " and " schedule form " is it posible to make the form available for a certain amount of posts for that logged in user ? Giving the user the ability to post only say 3 posts per day?

    Posted 12 years ago on Monday July 23, 2012 | Permalink
  2. Please see this. I think it's exactly what you're looking for:
    http://gravitywiz.com/2012/04/25/limit-user-to-one-submission-per-time-period/

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  3. thanks Chris

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  4. Sure thing.

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  5. elizabethanne
    Member

    this is great! any thoughts on editing that code to limit it to x posts per time period, instead of just one per time period? thank you!

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  6. I'm sure it can be done. I thought if you wanted to allow three times per 24 hours, you could limit it to once every 8 hours, but that's not equivalent (maybe I want to enter three times in 5 minutes and then come back tomorrow?)

    The way it works now is the time of the last submission is stored, and if that occurred less than "limit_time" seconds ago, prevent another submission. To extend that, you could count submissions by this user which occurred less than "limit_time" seconds ago. If there were less than "submission_limit" (a new variable to hold the number permitted in "limit_time") entries, then allow another entry. If the number of submissions is equal to to the "submission_limit", then prevent another submission.

    Sounds like an interesting extension of this. If you give it a go, please post your code here and we'l take a look. Thanks.

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  7. Hi

    Getting syntax error on line 120

    add_filter('gform_get_form_filter', create_function('', "return '<div class="limit-message">$limit_message</div>';") );
        }
    
        return $form;
    }
    ?>

    full code with changed form id only

    <?php add_action('gform_pre_render_2', 'gform_limit_submissions');
    function gform_limit_submissions($form){
        global $wpdb;
    
        $limit_message = 'You may only submit this form once every 24 hours.';
        $limit_time = 86400; // must be specified in seconds; 86400 seconds is equal to 24 hours
    
        /* You do not need to edit below this line */
    
        $current_user = wp_get_current_user();
        $last_submission = $wpdb->get_var($wpdb->prepare("SELECT date_created FROM {$wpdb->prefix}rg_lead WHERE created_by = %d and form_id = %d ORDER BY date_created DESC", $current_user->ID, $form['id']));
    
        if(empty($last_submission))
            return $form;
    
        $time_out = strtotime($last_submission) + $limit_time;
        $current_time = time();
    
        if($current_time > $time_out)
            return $form;
    
        $is_submit = rgpost("is_submit_{$form['id']}");
    
        if(!$is_submit) {
            add_filter('gform_get_form_filter', create_function('', "return '<div class="limit-message">$limit_message</div>';") );
        }
    
        return $form;
    }
    ?>
    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  8. I can't correlate line 120 to that code sample with 30 lines, but this line needs to be changed:

    [php]
    add_filter('gform_get_form_filter', create_function('', "return '<div class="limit-message">$limit_message</div>';") );

    Change it to this:

    [php]
    add_filter('gform_get_form_filter', create_function('', "return '<div class=\"limit-message\">$limit_message</div>';") );

    The double quotes in the div need to be back slashed.

    Posted 12 years ago on Tuesday July 24, 2012 | Permalink
  9. thanks Chris this is tested and works perfect!

    <?php add_action('gform_pre_render_2', 'gform_limit_submissions');
    function gform_limit_submissions($form){
        global $wpdb;
    
        $limit_message = '<strong>Oops!</strong> You may only submit a new classified ad<br /> every 5 minutes  and a total of 25 every 24 hours.<br /> You may want to read <br />(<em> Posting your ads in high competition topics ....</em> ) <br /> under (<em> Help / Edit  Ads</em> )  tab above as you wait.<br /> Your last ads keywords selection should have bin <br /> chosen with pinpoint topic accuracy after reading<br /> this. Doing this step will make you money by<br /> putting your ads on page 1# of all search engines!<br /> <strong>Note:</strong> If you post something in the <strong>wrong</strong> category<br /> for example: a ( <em>house for rent</em> ) in
    ( <em>services</em>),<br /> it will be <strong>deleted</strong> without warning within reason.<br /> You may also post <strong>duplicate</strong> ads but change the <br />title and keywords each time so its rated as<br /> ( <em>new content</em> ). <br /><br /><br /><br /><br /><br />
    <strong>Thank you</strong> for your patients as we review your last<br /> classified ad.<br /> Less then 3 minutes to go!';
        $limit_time = 300; // must be specified in seconds; 86400 seconds is equal to 24 hours
    
        /* You do not need to edit below this line */
    
        $current_user = wp_get_current_user();
        $last_submission = $wpdb->get_var($wpdb->prepare("SELECT date_created FROM {$wpdb->prefix}rg_lead WHERE created_by = %d and form_id = %d ORDER BY date_created DESC", $current_user->ID, $form['id']));
    
        if(empty($last_submission))
            return $form;
    
        $time_out = strtotime($last_submission) + $limit_time;
        $current_time = time();
    
        if($current_time > $time_out)
            return $form;
    
        $is_submit = rgpost("is_submit_{$form['id']}");
    
        if(!$is_submit) {
          add_filter('gform_get_form_filter', create_function('', "return '<div class=\"limit-message\">$limit_message</div>';") );
        }
    
        return $form;
    }
    ?>
    Posted 12 years ago on Wednesday July 25, 2012 | Permalink
  10. Thanks a lot for posting that. Much appreciated.

    Posted 12 years ago on Wednesday July 25, 2012 | Permalink