I have a 4 Step multi step form.
On step 3 I trigger a function via AJAX to send a notification.
However it is only sending on the form submit.
To test I used wp_mail
which sends on Step 3.
<?php
public static function instant_quote_step_2_notification() {
$form_id = $_POST['form_id'];
$form = GFAPI::get_form( $form_id );
$input_values = $_POST['input_values'];
$source_url = $_SERVER['HTTP_HOST'];
// Create a makeshift Entry object
$entry = array(
'id' => '140',
'form_id' => '1',
'post_id' => '60395',
'date_created' => '2023-01-31 19:55:20',
'date_updated' => '2023-01-31 19:55:20',
'is_starred' => '0',
'is_read' => '1',
'ip' => '127.0.0.1',
'source_url' => $source_url,
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
'currency' => 'USD',
'payment_status' => null,
'payment_date' => null,
'payment_amount' => null,
'payment_method' => null,
'transaction_id' => null,
'is_fulfilled' => null,
'created_by' => '38',
'transaction_type' => null,
'status' => 'trash',
15 => '3002',
18 => 'Richmond',
20 => $input_values['zip_code'],
5 => $input_values['square_footage'],
35 => $input_values['bed_baths'],
6 => $input_values['service_frequency'],
22 => $input_values['type_of_other'],
'9.3' => $input_values['first_name'],
'9.6' => $input_values['last_name'],
10 => $input_values['email'],
11 => $input_values['phone_number'],
27 => $input_values['text_friendly_number'],
23 => $input_values['how_did_you'],
13 => $input_values['pets'],
14 => $input_values['rooms'],
19 => $input_values['recipients'],
40 => $input_values['first_cleaning_price'],
41 => $input_values['every_week_price'],
52 => $input_values['every_week_frequency_text']
);
// Fails - This only sends on Form Submission
$return = GFAPI::send_notifications( $form, $entry, 'instant_quote_step_2' );
wp_send_json( $return );
// Test with wp_mail
// Success - This sends on Step 3
$to = 'emailsendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <support@example.com>');
wp_mail( $to, $subject, $body, $headers );
die();
}