MODX Community

FormIT and PARDOT

Does anyone have any guidance for creating a custom FormIT hook to submit form content to Pardot?

I’d like to make the hook literally just submit the form to a PARDOT form handler - so scaleable enough to be useful for any form regardless of fields. I don’t want to have to create new hooks for every form I have to make. I’d like to be able to specify the Pardot form handler URL in the FormIt call, and that’s all she wrote.

Any tips or examples would be appreciated.

If pardot comes with its own form handler, what do you need formit for?

I’d like to do a number of other things locally - save the data using formit - handle some email processing. Just a number of possibilities actually.

Creating hooks for FormIt is quite doable, you first need to know how to send information to Pardot. You can see examples here: http://developer.pardot.com/#using-the-api

But with FormIt, it’s then a matter of creating a custom Hook to get the data from FormIt. Here’s the docs on FormIt hooks: https://docs.modx.com/current/en/extras/formit/formit.hooks#registering-custom-hooks

1 Like

For anyone who’s interested, I have this fully working beautifully now with this custom FormIt hook:
Remember to include the two required parameters in your FormIt call - documented in the snippet code with examples.

<?php
# PARDOT FORM HANDLER HOOK
# Required parameters:
# pardotFormHandler - the URL supplied by your Pardot settings of the form handler
# example: &pardotFormHandler=`http://my.pardotdomain.com/l/736459/2020-07-24/9xc3fm`
#
# pardotReferringPage - the full URL to the referring page
# example: &pardotReferringPage=`[[~[[*id]]? &scheme=`full`]]`

$post_data = $hook->getValues();

# UNCOMMENT BELOW to LOG TEST
#$modx->log(xPDO::LOG_LEVEL_ERROR,$pardotFormHandler.'-'.$pardotReferringPage);

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//create cURL connection
$curl_connection = curl_init($pardotFormHandler);

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_REFERER, "$pardotReferringPage");

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
##print_r(curl_getinfo($curl_connection));

if (curl_errno($curl_connection)){
    $modx->log(xPDO::LOG_LEVEL_ERROR,curl_errno($curl_connection) . '-' . curl_error($curl_connection));
}

//close the connection
curl_close($curl_connection);

return true;  //<-- if you omit this or return false, your form won't validate
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.