Themergency fooplugins.com

Stop Gravity Forms from Creating Form Entries

| 15 Comments

There are cases when you want to allow your site visitors to add content to your WordPress blog from a front end form. The best (and easiest) way to accomplish this is to use Gravity Forms and our Gravity Forms + Custom Post Types Addon. For those that don’t know, the addon allows your site visitors to capture custom post types from a front end Gravity Form.

So if your form is creating posts in your WordPress database, do you really need the form to also create an entry? (or a lead as it’s called in the Gravity Forms code). I think in most cases not.

Someone also asked me if I could stop Gravity Forms from creating these entry database records, so I looked into it. I could not find a way, using the existing Gravity Forms hooks, to stop the form from creating an entry/lead in the database.

But then someone pointed me towards a comment on a recent article written on yoast.com, and Simon provided a link to some code in pastebin which does exactly what we want. It deletes all the associated entry/lead data after the form has been submitted. Admittedly, it would be better to not insert the data into the database in the first place, but after looking into the code as mentioned above, that is not possible. So this is a great solution!

Here is the code:

2 things to note with the code:

  1. line 2 has a syntax error and has an unnecessaryparenthesis ‘)’
  2. the code will delete ALL entries for ALL forms. Please read the code comments to see how to target specific forms.

So now the question: Should I create a small plugin that does this? And include a settings page where you can configure which forms delete their entries/leads?

7 comments
  Livefyre
  • Get Livefyre
  • FAQ
DaveTasker
DaveTasker

I don't think this will delete any file uploads

jmarx34
jmarx34

So did you ever create the plugin?

I'm trying to run this (in my theme's functions.php file) and nothing seems to be happening.  Any thoughts on debugging and/or ways to ensure it runs?  And would this eliminate entries already in the db, or just future ones?

Perfect concept for what I need, if I can get this to work.

Thanks!

Tevya
Tevya

Yes! Definitely! Plugin please. Some other scenarios are 1. using the GF User Registration Addon: you pipe all that data into the User's profile, so entries are redundant. 2. WooCommerce + Gravity Forms products addon: creates 2 entries for every order placed - once when adding to cart, and again at checkout. May not work for #2 as the 1st entry may be needed until checkout.

 

An alternate or additional functionality would be to put a max number of entries allowed to stay in the database, then the oldest beyond that would be auto-deleted. And/or a set number of days old, and entries are deleted beyond that time. That would solve #2 above and give you a window to keep/export entries if they're needed for backup or something.

RapidWeb
RapidWeb

This is the perfect solution I was looking for. I am trying to use Gravity Forms to act as a "Custom Search". However, I need to know "Where" to paste the code above (which file). Also, I need it to work on a few forms, but not on all. How can I do that?

anthea turner

I don't know what to say except that I have enjoyed reading. Nice website. I will keep visiting this website very often.

melquam
melquam

Lifesaver! My table sizes were getting overloaded and my host shut me down. Now I don't have to manually purge the entries!! Thank you!

themergency
themergency moderator

 @RapidWeb You can paste the code into your theme's function.php file

 

the only way to include some forms and not others is by specifying the action multiple times together with the correct form id. To remove entries from form with id's 2,3,5:

 

add_action( 'gform_post_submission_2', 'my_remove_entries' ), 10, 2 );

add_action( 'gform_post_submission_3', 'my_remove_entries' ), 10, 2 );

add_action( 'gform_post_submission_5', 'my_remove_entries' ), 10, 2 );