Last active
June 2, 2021 22:18
-
-
Save mbaxter91288/41bd9b12c8138c1dfca353aaa2f6261f to your computer and use it in GitHub Desktop.
Connecting Pardot to ON24 with WordPress and Forminator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', function() { | |
add_action( 'forminator_custom_form_submit_before_set_fields', function( $entry, $form_id, $field_data_array ) { | |
// add the ID of the Forminator form. This needs to be an `int` to | |
// pass the below if statement | |
$on24_forminator_form_id = 1234; | |
// if we're not submitting the above form, don't schedule the action | |
if ($form_id !== $on24_forminator_form_id) { | |
return; | |
} | |
// Schedule an action name 'make_names_uppercase_action' with specific first name data | |
as_enqueue_async_action( 'action_post_to_on24', [ | |
'entry' => $entry, | |
'form_id' => $form_id, | |
'field_data_array' => $field_data_array, | |
'event_id' => 'ADD YOUR EVENT ID HERE', | |
'event_key' => 'ADD YOUR EVENT KEY HERE', | |
] ); | |
}, 10, 3 ); | |
add_action( 'action_post_to_on24', function( $entry, $form_id, $field_data_array, $event_id, $event_key ) { | |
// these are our fields we want to send to ON24. Make sure the keys here match the | |
// parameter names from the API documentation | |
$data = [ | |
'firstname' => null, | |
'lastname' => null, | |
'email' => null, | |
'company' => null, | |
]; | |
// loop over all the submitted fields and look for our field names | |
foreach ($field_data_array as $field) { | |
// first make sure the field has a name and value | |
// some of the Forminator hidden fields do not have either or so it would error | |
if ( isset( $field['name'] ) && isset( $field['value'] ) ) { | |
// now loop over the fields we want to send to ON24 and assign our | |
// submitted field value to our $data array | |
foreach ($data as $name => $value) { | |
switch ($name) { | |
case 'name-1': | |
$data['firstname'] = $field['value']; | |
break; | |
case 'name-2': | |
$data['lastname'] = $field['value']; | |
break; | |
case 'email-1': | |
$data['email'] = $field['value']; | |
break; | |
case 'text-1': | |
$data['company'] = $field['value']; | |
break; | |
} | |
} | |
} | |
} | |
// now post this form's data to the form handler | |
$response = wp_remote_post( 'https://event.on24.com/utilApp/r?eventid=' . $event_id . '&key=' . $event_key, [ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'body' => $data, | |
'method' => 'POST', | |
] ); | |
// log any errors | |
if ( is_wp_error( $response ) ) { | |
$error_message = $response->get_error_message(); | |
error_log("Something went wrong: $error_message"); | |
} | |
}, 10, 5 ); | |
}, 5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
add_action( 'init', function() { | |
add_action( 'forminator_custom_form_submit_before_set_fields', function( $entry, $form_id, $field_data_array ) { | |
// add the ID of the Forminator form. This needs to be an `int` to | |
// pass the below if statement | |
$on24_forminator_form_id = 1234; | |
// if we're not submitting the above form just stop | |
if ($form_id !== $on24_forminator_form_id) { | |
return; | |
} | |
// these are our fields we want to send to ON24. Make sure the keys here match the | |
// parameter names from the API documentation | |
$data = [ | |
'firstname' => null, | |
'lastname' => null, | |
'email' => null, | |
'company' => null, | |
]; | |
// loop over all the submitted fields and look for our field names | |
foreach ($field_data_array as $field) { | |
// first make sure the field has a name and value | |
// some of the Forminator hidden fields do not have either or so it would error | |
if ( isset( $field['name'] ) && isset( $field['value'] ) ) { | |
// now loop over the fields we want to send to ON24 and assign our | |
// submitted field value to our $data array | |
foreach ($data as $name => $value) { | |
switch ($name) { | |
case 'name-1': | |
$data['firstname'] = $field['value']; | |
break; | |
case 'name-2': | |
$data['lastname'] = $field['value']; | |
break; | |
case 'email-1': | |
$data['email'] = $field['value']; | |
break; | |
case 'text-1': | |
$data['company'] = $field['value']; | |
break; | |
} | |
} | |
} | |
} | |
// set your ON24 event ID and key | |
$event_id = 'ADD YOUR EVENT ID HERE'; | |
$event_key = 'ADD YOUR EVENT KEY HERE'; | |
// now post this form's data to the form handler | |
$response = wp_remote_post( 'https://event.on24.com/utilApp/r?eventid=' . $event_id . '&key=' . $event_key, [ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'body' => $data, | |
'method' => 'POST', | |
] ); | |
// log any errors | |
if ( is_wp_error( $response ) ) { | |
$error_message = $response->get_error_message(); | |
error_log("Something went wrong: $error_message"); | |
} | |
}, 10, 3 ); | |
}, 5); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
add_action( 'init', function() { | |
add_action( 'forminator_custom_form_submit_before_set_fields', function( $entry, $form_id, $field_data_array ) { | |
}, 10, 3 ); | |
}, 5); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
// these are our fields we want to send to ON24. Make sure the keys here match the | |
// parameter names from the ON24 API documentation | |
$data = [ | |
'firstname' => null, | |
'lastname' => null, | |
'email' => null, | |
'company' => null, | |
]; | |
// loop over all the submitted fields and look for our field names | |
foreach ($field_data_array as $field) { | |
// first make sure the field has a name and value | |
// some of the Forminator hidden fields do not have either or so it would error | |
if ( isset( $field['name'] ) && isset( $field['value'] ) ) { | |
// now loop over the fields we want to send to ON24 and assign our | |
// submitted field value to our $data array | |
foreach ($data as $name => $value) { | |
switch ($name) { | |
case 'name-1': | |
$data['firstname'] = $field['value']; | |
break; | |
case 'name-2': | |
$data['lastname'] = $field['value']; | |
break; | |
case 'email-1': | |
$data['email'] = $field['value']; | |
break; | |
case 'text-1': | |
$data['company'] = $field['value']; | |
break; | |
} | |
} | |
} | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
... | |
// set your ON24 event ID and key | |
$event_id = 'ADD YOUR EVENT ID HERE'; | |
$event_key = 'ADD YOUR EVENT KEY HERE'; | |
// now post this form's data to the form handler | |
$response = wp_remote_post( 'https://event.on24.com/utilApp/r?eventid=' . $event_id . '&key=' . $event_key, [ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'body' => $data, | |
'method' => 'POST', | |
] ); | |
// log any errors | |
if ( is_wp_error( $response ) ) { | |
$error_message = $response->get_error_message(); | |
error_log("Something went wrong: $error_message"); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment