I have no way to test this, but the structure looks like so.
function pushMauticForm( $vendorId, $userId, $data, $formId, $ip = null ) {
//get array of form data;
//example: match mautic label (left) with form label ($_REQUEST['vendor-owner-firstname']
// parse the request args and merge with our defaults
// this ensures we don't have to do a bunch of isset checks.
$args = wp_parse_args( $_REQUEST, array (
'vendor-owner-firstname' => '',
'vendor-owner-lastname' => '',
'vendor-email' => '',
'more_data' => '',
) );
// load up the data
$data[ 'firstname' ] = $args[ 'vendor-owner-firstname' ];
$data[ 'last_name' ] = $args[ 'vendor-owner-lastname' ];
$data[ 'email' ] = $args[ 'vendor-email' ];
$data[ 'more_data' ] = $args[ 'more_data' ];
//set Mautic form ID
$formId = '3';
$data[ 'formId' ] = $formId;
// return has to be part of the form data array
if ( ! isset( $data[ 'return' ] ) ) {
$data[ 'return' ] = 'http://where-to-redirect.com';
}
// set the payload
// NOTE: It's confusing using 2 different $data vars... but $data is a new thing now
$data = array ( 'mauticform' => $data );
// Change [path-to-mautic] to URL where your Mautic is
$formUrl="http://[path-to-mautic]/form/submit?formId=" . $formId;
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $formUrl );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $data ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ( "X-Forwarded-For: $ip" ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
curl_close( $ch );
return $response;
}