I am using Gravity forms and I have got it making an auto notification. This notification happens after my android app connects to it and adds an entry. My issue is that it does not perform variable replacement.
So for example Subject in the form editor is defined as New Moving House Apps submission from {Full Name:2}
But the email ends up as New Moving House Apps submission from
All form variables are replaced with nothing in the email. but if i check the entry out in the website it is there.
I have added my code to the post_entries function in the Gravity Forms WebApi as follows:
public function post_entries($data, $form_id = null) {
$this->authorize('gravityforms_edit_entries');
$result = GFAPI::add_entries($data, $form_id);
if (is_wp_error($result)) {
$response = $this->get_error_response($result);
$status = $this->get_error_status($result);
} else {
$status = 201;
$response = $result;
// This is the form object from Gravity Forms.
$form = \GFAPI::get_form($form_id);
$event = 'form_submission';
$notifications = GFCommon::get_notifications_to_send($event, $form, $lead[0]);
$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);
}
$this->end($status, $response);
}
EDIT: here's the working code with Naomi's help
public function post_entries( $data, $form_id = null ) {
$this->authorize( 'gravityforms_edit_entries' );
$result = GFAPI::add_entries( $data, $form_id );
if ( is_wp_error( $result ) ) {
$response = $this->get_error_response( $result );
$status = $this->get_error_status( $result );
} else {
$status = 201;
$response = $result;
$lead = \GFAPI::get_entry($result);
// This is the form object from Gravity Forms.
$form = \GFAPI::get_form($form_id);
$event ='form_submission';
$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 );
}
$this->end( $status, $response );
}