Instantly share code, notes, and snippets.

Embed
What would you like to do?
Programmatically Trigger Gravity Forms Notification
<?php
function send_notification ( $event, $form, $lead ) {
$notifications = GFCommon::get_notifications_to_send( $event, $form, $lead );
$notifications_to_send = array();
//running through filters that disable form submission notifications
foreach ( $notifications as $notification ) {
if ( apply_filters( "gform_disable_notification_{$form['id']}", apply_filters( 'gform_disable_notification', false, $notification, $form, $lead ), $notification, $form, $lead ) ) {
//skip notifications if it has been disabled by a hook
continue;
}
$notifications_to_send[] = $notification['id'];
}
GFCommon::send_notifications( $notifications_to_send, $form, $lead, true, $event );
}
?>
@derpoho

This comment has been minimized.

derpoho commented Feb 5, 2015

Interesting that you set it to hidden, and i found it via Google. ;)
Anyway, script works great, some additions:

  • The Event for a Form Submission is "form_submission"
  • The $form and $lead are not only the id`s but the full result from GFAPI::get_entry( ID ) or GFAPI::get_form( ID )
  • within the foreach loop you should extend (to only send to active notifications):
foreach ( $notifications as $notification ) {
    if ( apply_filters( "gform_disable_notification_{$form['id']}", apply_filters( 'gform_disable_notification', false, $notification, $form, $lead ), $notification, $form, $lead ) ) {
        //skip notifications if it has been disabled by a hook
        continue;
    }

if( $notification["isActive"] != "1" ) {
            continue;
        }

    $notifications_to_send[] = $notification['id'];
}
@michaelphipps

This comment has been minimized.

michaelphipps commented Mar 7, 2015

Somehow, I've found this page as well!

I've used the code with clubdesign's suggestions (thx!), but I've hacked the webapi. Any idea what hook would I use if I wanted to build a separate plugin that adds notification sending when entries are submitted via the webapi?

@wlarch

This comment has been minimized.

wlarch commented Jun 10, 2015

Greetings,

I was able to programmatically send a notification as explained in this thread.
Although, I cannot manage to send a disabled notification using this method.

The problem explanined :

I have two different notifications to send :

A - One is sent when form is submitted. (OK)
B - The other is sent manually using this method.

I disabled the notification that is not sent when the form is submitted.
Still I cannot manage to send the manual notification for the disable one.

How could this be done ?
Thanks for your support.

@zamson

This comment has been minimized.

zamson commented Jul 22, 2015

@wlarch

Did you ever solve this? Looking for exactly the same solution.

@vainucleo

This comment has been minimized.

vainucleo commented Feb 18, 2016

Sorry I'm a really newbie but after weeks of searching this seems to be exactly what I'm looking for.

I would like to send a GF notification just after a new user click the link in the email and activate the account.

Where am I supposed to paste your code?

Thanks in advance

@offordscott

This comment has been minimized.

offordscott commented Apr 9, 2017

In WordPress, I would like the ability to check if a certain field from a Gravity Forms entry has been updated or not by the user after X days has passed since they first submitted the form. On my site, the user fills in the form slowly over a period of a few months. Each time they come back to the site, they would edit their entry (I'm using Gravity View plugin).

But, if that database cell does not have any content in it by X date, I would like an email to go out to the user who submitted the form asking them to update the form (in case they forgot to come back or just got lazy).

There are all sort of plugins that can send out emails, like Woocommerce's "Follow Up Emails", but what I need is to schedule an email and, conditionally... if the user has not already filled out a specific Gravity Forms field by X date, the email should sent. If the user has filled out the field by X date, the email SHOULD NOT be sent to the user.

Any ideas?

@connistock

This comment has been minimized.

connistock commented Jul 22, 2018

I have a similar question as @offordscott. I need to send an email notification when form is approved. Currently, I have a notification for form received. I have included a hidden check box field with Approved, Pending, Incomplete, Duplicate options. I would like to create a email notification to be triggered when the Approved box has been selected. Is this possible? with this type of code. Any information where I can learn to create this action would be very helpful. Also, @offordscott did you get any response?

@anvilzephyr

This comment has been minimized.

anvilzephyr commented Aug 10, 2018

To send a notification after a manual edit to the entry (ie selecting 'Approved' in a radio button) use the 'gform_after_update_entry' action hook. Your notification should be conditional to the radio button value is 'Approved' if you don't want it to be sent immediately. Then after an update to the entry you can trigger the send. If the condition is then met, it will send.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment