Post

Gravity forms cheatsheet

This article is compilation of some of the more intricate Gravity Forms Functions and Features.

Overwrite css

Super hard to overwrite GF styles using classes. The simple way is just to use the id’s to overwrite the class styles.

1
2
3
  #gform_submit_button_18 {
    border-radius: 200px;
}

Submit Partial information.

On a multipage form you can capture partial information. (first page of the form) using an elite gravity forms addon called. The Gravity Forms Partial Entries Add-On. This addon comes free for all elite license holders.

Disable duplicate submissions

Below are some methods you can use to prevent duplicate form entries though your gravity forms

Disable Ajax form submissions

no ajax

If you don’t know the cause of the duplicate entries. One of the first things to try is to disable the Ajax form submissions and just use a static thank you page confirmation. If Ajax is the cause then fixing this issue is outside the scope of this tutorial but at least you have narrowed it down.

Enable no duplicates

Gravity forms has a built in option in the form settings for no duplicates. The requirements for this powerful feature is a field within the form that takes a unique value. Like an invoice number which would be unique.

enable no duplicates on the gravity forms field

Create your own unique id hidden field

If you’re form doesn’t have a field that takes a unique value the you can just create your own.

  • Add the following snippet your functions.php file
  • Create a hidden field on your form
  • Update the form-id and field-id in the below snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
add_filter("gform_field_value_uuid", "get_unique");
function get_unique(){
    $prefix = "SLP2017-"; // update the prefix here
    do {
        $unique = mt_rand();
        $unique = substr($unique, 0, 8);
        $unique = $prefix . $unique;
    } while (!check_unique($unique));
    return $unique;
}
function check_unique($unique) {
    global $wpdb;
    $table = $wpdb->prefix . 'rg_lead_detail';
    $form_id = 3; // update to the form ID your unique id field belongs to
    $field_id = 7; // update to the field ID your unique id is being prepopulated in
    $result = $wpdb->get_var("SELECT value FROM $table WHERE form_id = '$form_id' AND field_number = '$field_id' AND value = '$unique'");
    if(empty($result))
        return true;
    return false;
}

Stop Gravity Forms Duplicate Submissions and Notifications generate unique id

Add a surcharge fee to a Gravity Forms transaction

One thing I love about gravity forms is You can use gravity forms for some basic e-commerce functions. It’s a great option if you just need to take a simple payment or have a simple product list and woocommerce would be overkill. But what if you needed to add a surcharge? Which is a common E-commerce function. If using woo we would probably just get a free plugin to do this for us. How can we do this with gravity forms E-commerce?

Add a 0.25% surcharge to the transaction

Add a surcharge to form with one product value

  • Add a product field and set it to be of the calculation field type.
  • Add the following code to the product calculation field
0.0025 * {Payment Amount:2}

Add Surcharge to a Form with Multiple Products Surcharge

  • Multiply all the product price fields by their respective quantity fields
  • Add them all together
  • Wrap that calculation in ();
  • Multiple by 0.0025
(
{fieldname (Price):1.2}*{fieldname (Quantity):1.3} +
{fieldname (Price):6.2}*{fieldname (Quantity):6.3} +
{fieldname (Price):8.2}*{fieldname (Quantity):8.3} +
{fieldname (Price):7.2}*{fieldname (Quantity):7.3} +
{fieldname (Price):9.2}*{fieldname (Quantity):9.3} +
{fieldname (Price):10.2}*{fieldname (Quantity):10.3}
)*0.0025

Add css class to submit button

Add to functions.php

1
2
3
4
5
6
7
<?php
add_filter( 'gform_submit_button', 'add_custom_css_classes', 10, 2 );
function add_custom_css_classes( $button, $form ) {
  $button = str_replace( 'gform_button', 'btn btn-primary', $button );
  return $button;
}
?>

Shortcode usage

1
[gravityform id=1 title=false description=false ajax=true tabindex=49]

Show gravity forms label visibility setting

1
<?php  add_filter( 'gform_enable_field_label_visibility_settings', '__return_true' ); ?>

Dynamic email address

The gravityform for send email address is dynamically set from a value set in an acf field.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php function agent_notification( $notification, $form) {

  //http://wycks.wordpress.com/2014/02/26/using-a-wordpress-posts-meta-field-for-dynamic-gravity-form-emails/
   //This example is using a form with the id of 1
    if($form["id"] == 4){
        global $post;

        //the example email is stored in a post meta field called "_cmb_email"
        //$agent_email = get_post_meta( $post->ID , '_cmb_email', true );
        $agent_email = get_field('agent_email');
        $notification['to'] = $agent_email;

       return $notification;
    }
}


add_filter('gform_notification', 'agent_notification', 10, 3);

Add helpful form information to your forms notificaitons

Want to know where and what form submissions are coming from:

1
2
3
4
entry url: {entry_url}
form title: {form_title}
referer url: {referer}
form id: {form_id}

Debugging

find the error in the logs - turn on logging. then search the logs

failed uploads

check permissions of gravity forms uploads dir ~/public_html/wp-content/uploads/gravity_form

upload folders correspond to each form id 5-c98e649a52ea09baaf943f9be96d8d9f. eg: 5 is the form id for this uploads directory.

Cant find form entry when searching for id.

construct your own url

1
https://example.com/wp-admin/admin.php?page=gf_entries&view=entry&id=5&lid=54870
This post is licensed under CC BY 4.0 by the author.