Below is the snippet I need modified along with the details:
<?php
/*
* I need this function to essentially make a remote request (POST) to a service URL from a specific form, passing along remapped form submission values
* -- 1) Using forminator action "forminator_custom_form_submit_before_set_fields"
* -- 2) Need it to -only- work on a specific form or forms
* -- 3) Remap form submission values to match the api values which are listed below
* -- 4) Don't need it to send an email, only sbmit post data to api as an option
*
* Using snippet from: https://www.billerickson.net/contact-form-integration/
*/
add_action( 'forminator_custom_form_submit_before_set_fields', 'the_forminator_mailgun_connector', 10, 4 );
function the_forminator_mailgun_connector( $entry, $form_id, $field_data_array ) {
$api_url = 'https://path/to/my/api.php';
//I need this only to work on a specific form or forms
$form_id = 5;
$to_array = false;
$body = array( //I don't know the correct way to get the specific form field value here from forminator
'name' => Forminator_API::get_form_field( $form_id, 'name-1', $to_array ), //?
'email' => $field_data_array[''][$field_id]['value'], //?
'zipcode' => $fields['value'], //?
);
$request = wp_remote_post( $api_url, array( 'body' => $body ) );
// Simple error handling
if ( is_wp_error( $request ) ) {
$msg = "There was an error trying to subscribe a user to the mailing list.n";
$msg .= 'Error returned: ' . $error = $request->get_error_message() . "nn";
$msg .= "Contact the user below about the error and see if they want to be added to the mailing list manually.n";
$msg .= $body['name'] . ' ' . $body['email'] . ' ' . $body['zipcode'];
wp_mail( get_bloginfo( 'admin_email' ), 'The Mailgun Subscribe Error', $msg );
}
}