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:

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:

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.

# Required parameters:
# pardotFormHandler - the URL supplied by your Pardot settings of the form handler
# example: &pardotFormHandler=``
# pardotReferringPage - the full URL to the referring page
# example: &pardotReferringPage=`[[~[[*id]]? &scheme=`full`]]`

$post_data = $hook->getValues();


//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

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

//close the 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.