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.

Display number of form entries left per form

  1. Hi,

    I've got a few forms with limited entries and I would like to display for each form the remaining entries left for the form? Any hint if there is a variable I could grab, or do I need to get it directly from the DB?

    thanks in advance...

    Regards Marcel

    Posted 13 years ago on Sunday October 2, 2011 | Permalink
  2. Take a look at this form (submit if you want and check again):
    http://gravity.chrishajer.com/2011/07/22/where-are-you-from/

    Here is the code that accomplished it:
    http://pastebin.com/SzDRRvN9

    That's a pretty simple example, but it looks like you can use the gform_pre_render hook to determine how many entries have been submitted and subtract that from your limit.

    My limit was overall for the form, not per day or week. Also, I appended the text to the description, which means you need to show the description. If you want to show it somewhere else in the form, you will have to adjust that. Also, I did not account for the singular "1 entries left" case when it gets to the last one. Finally, entries in the trash are counted against the total number of entries.

    If you need help customizing this, please let us know.

    Posted 13 years ago on Monday October 3, 2011 | Permalink
  3. Hi Chris

    Thanks so much for your help! Definitely a great starting point! Only issue would be if there is more than 1 form I would need a loop for the ID's but off course like this I have control over the output text
    Best regards

    Marcel

    Posted 13 years ago on Monday October 3, 2011 | Permalink
  4. If you need more help please let us know.

    Posted 13 years ago on Monday October 3, 2011 | Permalink
  5. Hi Chris

    Thanks again for the great support. As mentioned This works perfect if I know exaclty which form ID's will be created. So my question would be if there is a possibility to add the filter to any form created with "limited" entries applied to it, and not by ID as it is at the moment. Would make it more flexible in my case!

    Thanks and regards Marcel

    Posted 13 years ago on Wednesday October 12, 2011 | Permalink
  6. Hi Marcel. Instead of the gform_pre_render_3, you can use gform_pre_render to process all forms, then use a condition to determine if your form should be one to show the limit and number left (i.e. run the function.)

    A form which has entries limited will have $form['limitEntriesCount'] set, so you can just wrap all your processing in a conditional.

    Something like this http://pastebin.com/zCnPeYR2

    You might have to figure out which test is appropriate in line 5. I used empty, but you might have to use "< 1" or "isset" or "is_null", whichever works in this case. I forget what the form object looks like when that value is not set. I think empty will work fine.

    Posted 13 years ago on Wednesday October 12, 2011 | Permalink
  7. Hi Chris,

    Can you demonstrate how one might use your proposed code for all forms in a way that doesn't require adding the $left value to the $forms['description'] variable? I basically need to be able to drop this variable into an html excerpt. I tried setting the function to simply "return $left;" but I get nothin when I echo $left out.

    Posted 13 years ago on Thursday October 27, 2011 | Permalink
  8. You have to return the $form when using the gform_pre_render filter, or there won't be a form.

    I added the value of $left to the form description, but you can assign it to any field in the form object using the gform_pre_render filter. You could pre-populate a hidden or visible field or whatever you want. I'm not sure what you do want to do with it though.

    Posted 13 years ago on Friday October 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.