Advertisement
chrishajer

apply processing only to forms with limited entries

Oct 12th, 2011
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. // http://www.gravityhelp.com/forums/topic/display-number-of-form-entries-left-per-form
  2. add_filter('gform_pre_render', 'show_entries_left');
  3. function show_entries_left($form) {
  4.     // see if this form has a limit set and we need to show how many are left
  5.     if(empty($form['limitEntriesCount'])) {
  6.         return $form;
  7.     }
  8.     // limit is set; continue processing
  9.     else {
  10.         // get the number of entries for this form
  11.         $entry_count = RGFormsModel::get_lead_count($form['id'], "", null, null, null, null);
  12.  
  13.         // subtract the entry count from the limit to determine how many are left
  14.         $left =  $form['limitEntriesCount'] - $entry_count;
  15.  
  16.         // append the number of entries left to the description displayed before the form
  17.         $form['description'] .= "Hurry! Only <strong>$left</strong> more entries will be accepted.";
  18.  
  19.         // return the form
  20.         return $form;
  21.     }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement