Skip to content

Instantly share code, notes, and snippets.

@unculturedswine
Last active December 13, 2022 17:47
Show Gist options
  • Save unculturedswine/ac64b36341ffa091a20e6b6a7093eab4 to your computer and use it in GitHub Desktop.
Save unculturedswine/ac64b36341ffa091a20e6b6a7093eab4 to your computer and use it in GitHub Desktop.
Using Pardot and Formidable
<?php
add_action('frm_after_create_entry', 'sendToPardotFormHandler', 30, 2);
function sendToPardotFormHandler($entry_id, $form_id){
if($form_id == 3){ //replace 3 with the id of the form
$args = array();
if(isset($_POST['item_meta'][XX])) //change XX to the field ID
$args['firstName'] = $_POST['item_meta'][XX]; //change 'firstName' to the named parameter to send
if(isset($_POST['item_meta'][XX])) //change XX to the field ID
$args['lastName'] = $_POST['item_meta'][XX]; //change 'lastName' to whatever you need
if(isset($_POST['item_meta'][XX])) //change XX to the field ID
$args['email'] = $_POST['item_meta'][XX]; //change 'email' to whatever you need
if(isset($_POST['item_meta'][XX])) //change XX to the field ID
$args['phone'] = $_POST['item_meta'][XX]; //change 'phone' to whatever you need
$result = wp_remote_post('https://example.com', array('body' => $args));
}
}
?>
@unculturedswine
Copy link
Author

unculturedswine commented Sep 20, 2016

Using Pardot Form Handlers has been rather hit-and-miss on my forms, and it's not as user-friendly as I was hoping it would be. The function up above is the most reliable way I've discovered of using Form Handlers with Wordpress and the Formidable plugin.

Please Note

  • For maximum reliability, I always specify pages on my website as the Success Location and the Error Location within the Pardot Form Handler. When I'd leave those fields as Referring URL I'd get too-many redirect errors
  • Put the above code inside your themes functions.php file (remove the PHP tags as necessary)
  • If using several different Form Handlers on your site, be sure to change the function name to be unique for each add_action (In the example above, the function name is sendToPardot
  • I have no idea what the 30, 2 is for in the code above. I got that from Formidable and having the same numbers on each function has not caused a problem

@asanger
Copy link

asanger commented Oct 10, 2016

👍 greatly appreciate you sharing this! Hugely helpful.

ps: The 30, 2 are the priority level and number of args, respectively. https://developer.wordpress.org/reference/functions/add_action/

@cawalley
Copy link

cawalley commented Nov 1, 2019

Hello, I'm working to integrate Formidable forms to Pardot using this method - is this method and code still valid?

@unculturedswine
Copy link
Author

unculturedswine commented Nov 2, 2019 via email

@unculturedswine
Copy link
Author

Needed to do this again, had to troubleshoot and ended up updating the code to use an array.

@gennadygomez
Copy link

Thanks for this code! Question - have you run into any issues with conditional fields? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment