0

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' => 'joe@jonas.com',
        '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>
Sem
  • 55
  • 5
  • Well looks like you are never using the `Pardot` class, and have errors turned off? – mardubbles May 26 '22 at 19:30
  • @mardubbles, do you have a specific way to view errors? What do you mean not using the Pardot class? I'm new to this, so I'd like to learn. – Sem May 26 '22 at 19:36
  • Are you testing in the console or a web browser? If the latter, then you can open dev tools in the browser. Usually Ctrl+Shift+I but may be a different key combo or menu option in the browser --= this is to see the immediate errors. – mardubbles May 26 '22 at 19:41
  • When I make the response, all I get back is a bunch of HTML markup, it doesn't submit anything but I get a response back with like a full HTML template. – Sem May 26 '22 at 19:42
  • I wonder if the keys used in the cURL request don't match up to what Pardot might be using? Like if I use `first_name`, would that be the key for First Name in Pardot? – Sem May 26 '22 at 19:44
  • It be interesting to see what the `response back with like a full HTML template.` says. – mardubbles May 26 '22 at 19:45
  • Likely what you get back in terms of a `full HTML template.` and no work done as you indicate, is the API's error response, which we can use to debug to come up with a working solution. – mardubbles May 26 '22 at 19:47
  • Let me run a test now and I will update in like a minute. – Sem May 26 '22 at 19:47
  • I just updated it with the error response. – Sem May 26 '22 at 19:51
  • Would the key for `Email` be like `926923_56554pi_926923_56554` instead of `email` which is shown in the `for="926923_56554pi_926923_56554"` section? – Sem May 26 '22 at 19:52
  • Looks like your "curl" request is just getting a "document" and not an api/endpoint answer. – mardubbles May 26 '22 at 19:56
  • I did notice that your `curl` commands looked at bit off. – mardubbles May 26 '22 at 19:57
  • @mardubbles would you be able to post an answer with possibly an updated one? It would be much appreciated! I can't seem to figure out what's wrong in the cURL request. – Sem May 26 '22 at 19:58
  • I will be most obliged. One moment... – mardubbles May 26 '22 at 19:59

1 Answers1

0

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.

Adam Erstelle
  • 2,454
  • 3
  • 21
  • 35
  • Thanks for letting me know Adam! This is super helpful - I just had one question, with the field names, how did you come up with the `1016038` number? Is there a specific conversation that gets done? – Sem May 27 '22 at 11:36
  • You need to inspect the HTML of the Pardot-generated form. Pardot creates these numbers for its picklist values. It's kind of a pain. – Adam Erstelle May 28 '22 at 17:42