Gravity Forms – enable automatic entry deletion

How can I prevent Gravity Forms from saving entries?

This is a question that comes up every so often. The answer is, you can't. Gravity Forms needs to save the entry for those values to be available for use in notifications, confirmations and to send them to third-party services.

What you can do however is delete the entry at the end of the submission process. The following code snippet will add a checkbox to the Form Settings page, check the box and the entry will automatically be deleted.

Delete Entries

This snippet requires the latest version of Gravity Forms be installed, Gravity Forms 1.8.6 was released earlier today so go and update. You can then add the following code snippet to your theme functions.php file or custom functionality plugin, you don't need the <?php from line 1.

Converting the Gravity Forms next, previous and submit inputs to buttons

Last time I covered Removing the Gravity Forms submit button, this time I'm going to show you how you can use the same gform_submit_button hook along with two new hooks, gform_next_button and gform_previous_button, to change the <input> element to a <button> element with an addtional <span> element to contain the label.

Let's start by taking a look at what the HTML for the average next, previous and submit buttons look like:

<input type='button' id='gform_next_button_245_1' class='button gform_next_button' value='Next' tabindex='2' onclick='jQuery("#gform_target_page_number_245").val("2"); jQuery("#gform_245").trigger("submit",[true]); '/>
<input type='button' id='gform_previous_button_245_4' class='button gform_previous_button' value='Previous' tabindex='5' onclick='jQuery("#gform_target_page_number_245").val("1"); jQuery("#gform_245").trigger("submit",[true]); '/>
<input type='submit' id='gform_submit_button_245' class='button gform_button' value='Submit' tabindex='8' onclick='if(window["gf_submitting_245"]){return false;}  if( !jQuery("#gform_245")[0].checkValidity || jQuery("#gform_245")[0].checkValidity()){window["gf_submitting_245"]=true;} '/>

Notice the tabindex and onclick attributes, now here's the example from the documentation showing how you can change just the submit button:

// filter the Gravity Forms button type
add_filter("gform_submit_button", "form_submit_button", 10, 2);
function form_submit_button($button, $form){
    return "<button class='button' id='gform_submit_button_{$form["id"]}'><span>Submit</span></button>";

By using the above example you are losing some of the attributes, the onclick attribute is used to prevent duplicate form submissions and for next and previous buttons it's also responsible for actually moving from one page to another so ideally we want to keep that.

So, how can we improve on the above example so it keeps all the important attributes we need while also making it universal so it can handle all three button types, and for bonus points use whatever label you assign to the next, previous and submit buttons in the form editor. Here's the code, you would add it to your theme's functions.php file or custom functionality plugin, you don't need the <?php from line 1.

Now I bet you're wondering what that gets you, well here's what the HTML for the new next, previous and submit buttons would look like:

<button type="button" id="gform_next_button_245_1" class="button gform_next_button" tabindex="2" onclick='jQuery("#gform_target_page_number_245").val("2"); jQuery("#gform_245").trigger("submit",[true]); '><span>Next</span></button>
<button type="button" id="gform_previous_button_245_4" class="button gform_previous_button" tabindex="5" onclick='jQuery("#gform_target_page_number_245").val("1"); jQuery("#gform_245").trigger("submit",[true]); '><span>Previous</span></button>
<button type="submit" id="gform_submit_button_245" class="button gform_button" tabindex="8" onclick='if(window["gf_submitting_245"]){return false;}  if( !jQuery("#gform_245")[0].checkValidity || jQuery("#gform_245")[0].checkValidity()){window["gf_submitting_245"]=true;} '><span>Submit</span></button>

So there you have it, all the important attributes from the <input> elements have been transferred over to the new <button> elements.

Unless your theme contains some <button> specific styles they will be rendered using the browsers default styles but you can of course add your own CSS to your theme stylesheet to style the buttons however you like. Here's one article that explains how you can style <button> elements

Removing the Gravity Forms submit button

So you're creating a really cool form with Gravity Forms, maybe you're using Number fields to create a calculator, but you've hit a snag. All forms created using Gravity Forms have a submit button, and your awesome calculator doesn't need one, what are you going to do?

Well you could hide the button using CSS, the following when added to your theme stylesheet or wherever you add custom CSS would hide the footer therefore hiding the submit button.

.gform_wrapper .gform_footer {
    display: none;

The above example would affect all forms so if you only want to target a specific form you would switch from using the form wrapper class selector to using the form wrapper ID like so:

#gform_wrapper_10 .gform_footer {
    display: none;

Another way would be to hide it using conditional logic, you would do this by editing the form settings and configuring a condition for the form button that you know can never be met therefore your submit button will never be shown.

The above methods are fine but the submit button is still there, what if there was a way to actually remove the button, good news, there is. Gravity Forms has many hooks you can use, in this case gform_submit_button is the hook Gravity Forms provides so you can change the submit button, the example in the documentation shows how you can replace the <input> element with a <button> element.

But how do you use that hook to remove the submit button, well it's easier than you'd think, WordPress has a couple of readymade functions you can call on, so instead of using a custom function you can call on the WordPress __return_false function, by returning false to gform_submit_button no button will be included with the form.

The example below will remove the submit button from the form with the id 10

add_filter( 'gform_submit_button_10', '__return_false' );

To remove the submit button from all forms, simply remove the form id from the end of the hook name like so

add_filter( 'gform_submit_button', '__return_false' );

So one line of code added to your theme's functions.php file or custom functionality plugin and say goodbye to the submit button. How easy is that!

Include HTML fields and exclude other fields from Gravity Forms notifications

The Gravity Forms {all_fields} merge tag in notifications includes all fields for which the user entered or selected a value, it doesn't include HTML fields, Section Break descriptions, nor does it allow you to omit specific fields from the notification.

By adding the following code to your themes functions.php file you will gain the ability to include HTML fields, and Section Break field descriptions of your choice in the notifications and exclude fields of your choice from appearing in the notifications.

HTML fields will be treated just like any other field so you may want to give them more meaningful labels otherwise the notification will just include the default "HTML Block" label.

Also if your form uses conditional logic and your HTML field is hidden at the time the form is submitted the HTML field will not be included in the notification. Note: gf_exclude does not work with pricing fields.

Original posted on Google+

Some important news about how we are going to be handling Gravity Forms standard support as of today

Some important news about how we are going to be handling Gravity Forms standard support as of today

We are announcing a major change to how we handle standard support. It will no longer be handled via a forum system. We will now be handling standard support requests via the same ticketing system we utilize for Contact Us and Priority Support requests. Due to Gravity Forms explosive user growth …

If you use Gravity Forms and have recently started to experience issues installing add-ons or updates…

If you use Gravity Forms and have recently started to experience issues installing add-ons or updates you may want to check out the latest blog post over on #gravityforms  

We have seen a rise in the number of people reporting issues automatically updating Gravity Forms, downloading or updating Gravity Forms add-ons from within their WordPress Dashboard. Upon investigation, we have discovered that the issue is typically due to a shared IP address being blacklisted …