Submit Pardot Form using cURL request

709 Views Asked by At

So I am looking into utilizing Pardot and submitting a form using a cURL request, but I'm having some issues with the submission.

So let's say the iFrame that Pardot provides works well and it looks like this:

<iframe src="https://go.test.com/l/926923/2022-05-25/3l5rr" width="100%" height="500" type="text/html" frameborder="0" allowTransparency="true" style="border: 0"></iframe>

Then on Pardot, I have the following form fields:

enter image description here


Now, I am trying to use a cURL request to execute a test submission instead of a iFrame so that Pardot data can show up in the "Prospects (Submissions)" using this:

$curl = curl_init();

curl_setopt(
    $curl,
    CURLOPT_URL,
    'https://go.test.com/l/926923/2022-05-25/3l5rr'
);
curl_setopt(
    $curl,
    CURLOPT_POST,
    true
);
curl_setopt(
    $curl,
    CURLOPT_POSTFIELDS,
    [
        'email' => '[email protected]',
        'inquiry' => 'General',
        'office_name' => 'Corporate Office',
        'first_name' => 'Joe',
        'last_name' => 'Jonas',
        'message' => 'Test',
    ]
);
curl_setopt(
    $curl,
    CURLOPT_RETURNTRANSFER,
    true
);
$result = curl_exec($curl);
error_log(print_r($result, true));
curl_close($curl);

For some reason, when the cURL request runs, nothing happens - Does someone know how to properly execute a cURL request to call a POST to submit a Pardot form?


This is the error response:

[26-May-2022 19:48:31 UTC] <!DOCTYPE html>
<html>
    <head>
        <base href="https://go.fleishmanhillard.com" >
        <meta charset="utf-8"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta name="description" content=""/>
        <title></title>
        
    <script type="text/javascript" src="https://go.test.com/js/piUtils.js?ver=2021-09-20"></script><script type="text/javascript">
piAId = '927923';
piCId = '42983';
piHostname = 'pi.pardot.com';
if(!window['pi']) { window['pi'] = {}; } pi = window['pi']; if(!pi['tracker']) { pi['tracker'] = {}; } pi.tracker.pi_form = true;
(function() {
    function async_load(){
        var s = document.createElement('script'); s.type = 'text/javascript';
        s.src = ('https:' == document.location.protocol ? 'https://pi' : 'http://cdn') + '.pardot.com/pd.js';
        var c = document.getElementsByTagName('script')[0]; c.parentNode.insertBefore(s, c);
    }
    if(window.attachEvent) { window.attachEvent('onload', async_load); }
    else { window.addEventListener('load', async_load, false); }
})();
</script></head>
    <body>
        <form accept-charset="UTF-8" method="post" action="https://go.test.com/l/926923/2022-05-25/3l5rr" class="form" id="pardot-form">
        
            <p class="errors">Please correct the errors below:</p>
        

        
            <p class="form-field  Type pd-select required   error ">
                
                    <label class="field-label" for="926923_56599pi_926923_56599">Type of Inquiry</label>
                

                <select name="926923_56599pi_926923_56599" id="926923_56599pi_926923_56599" class="select" onchange=""><option value="" selected="selected"></option>
<option value="1016038">New Business</option>
<option value="1016041">Crisis Management</option>
<option value="1016044">Media</option>
<option value="1016047">General</option>
<option value="1016050">Careers</option>
</select>
                
            </p>
            <div id="error_for_926923_56599pi_926923_56599" style="display:none"></div>
            
                <p class="error no-label">This field is required</p>
            
        
            <p class="form-field  email pd-text required   error ">
                
                    <label class="field-label" for="926923_56554pi_926923_56554">Email</label>
                

                <input type="text" name="926923_56554pi_926923_56554" id="926923_56554pi_926923_56554" value="" class="text" size="30" maxlength="255" onchange="" onfocus="" />
                
            </p>
            <div id="error_for_926923_56554pi_926923_56554" style="display:none"></div>
            
                <p class="error no-label">This field is required.</p>
            
        
            <p class="form-field  first_name pd-text required   error ">
                
                    <label class="field-label" for="926923_56545pi_926923_56545">First Name</label>
                

                <input type="text" name="926923_56545pi_926923_56545" id="926923_56545pi_926923_56545" value="" class="text" size="30" maxlength="40" onchange="" onfocus="" />
                
            </p>
            <div id="error_for_926923_56545pi_926923_56545" style="display:none"></div>
            
                <p class="error no-label">This field is required.</p>
            
        
            <p class="form-field  last_name pd-text required   error ">
                
                    <label class="field-label" for="926923_56548pi_926923_56548">Last Name</label>
                

                <input type="text" name="926923_56548pi_926923_56548" id="926923_56548pi_926923_56548" value="" class="text" size="30" maxlength="80" onchange="" onfocus="" />
                
            </p>
            <div id="error_for_926923_56548pi_926923_56548" style="display:none"></div>
            
                <p class="error no-label">This field is required.</p>
            
        
            <p class="form-field  company pd-text     ">
                
                    <label class="field-label" for="926923_56551pi_926923_56551">Company</label>
                

                <input type="text" name="926923_56551pi_926923_56551" id="926923_56551pi_926923_56551" value="" class="text" size="30" maxlength="255" onchange="" onfocus="" />
                
            </p>
            <div id="error_for_926923_56551pi_926923_56551" style="display:none"></div>
            
        

        
    <p style="position:absolute; width:190px; left:-9999px; top: -9999px;visibility:hidden;">
        <label for="pi_extra_field">Comments</label>
        <input type="text" name="pi_extra_field" id="pi_extra_field"/>
    </p>
        

        <!-- forces IE5-8 to correctly submit UTF8 content  -->
        <input name="_utf8" type="hidden" value="&#9731;" />

        <p class="submit">
            <input type="submit" accesskey="s" value="" />
        </p>
    



<script type="text/javascript">
//<![CDATA[

    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if(anchor.getAttribute("href")&&!anchor.getAttribute("target")) {
            anchor.target = "_top";
        }
    }
        
//]]>
</script>
<input type="hidden" name="hiddenDependentFields" id="hiddenDependentFields" value="" /></form>
<script type="text/javascript">(function(){ pardot.$(document).ready(function(){ (function() {
    var $ = window.pardot.$;
    window.pardot.FormDependencyMap = [];

    $('.form-field-primary input, .form-field-primary select').each(function(index, input) {
        $(input).on('change', window.piAjax.checkForDependentField);
        window.piAjax.checkForDependentField.call(input);
    });
})(); });})();</script>
    </body>
</html>
1

There are 1 best solutions below

2
On

Pardot Form field names are numeric in nature and quite tough to script.

If possible, take a look at Pardot Form Handlers (which are just a back-end of a Form). Those are ideal for scripting / integrating with as they are a lot simpler and allow you to define the field name.

If you need to use the form (for actual testing of the form, and not for ingesting data) you will need to replace your payload's field names with the names on the form. Sor for your picklist, you would have: 926923_56599pi_926923_56599 = 1016038 for New Business.

Also, be sure that your values are application/x-www-url-encoded.