1

I've got two different remote forms which I need to submit data to. The first one is an http form, and it works just fine. Submit > redirect to result page > return response as variable.

The second one lives on an https page, and it just doesn't work, no matter what I try. So here's what I'm working with:

First form's form tag

<form method="post" name="entry_form" action="a_relative_page.asp?start=1">

Second form's form tag

<form method="post" novalidate enctype="multipart/form-data" action="https://asubdomain.formstack.com/forms/index.php" class="stuff" id="stuff1234567890">

Both buttons are completely unremarkable, with no fancy javascript, and look essentially like

<input type="submit">

And here's the PHP cURL request

    $post_data = http_build_query(
        array(
            'lots_of'   => 'values_here'
        )
    );
    $url = 'https://asubdomain.formstack.com/forms/a_page_with_form';
    $ch = curl_init($url);
    $opts = array(
        CURLOPT_SSL_VERIFYPEER  => FALSE,
        CURLOPT_SSL_VERIFYHOST  => FALSE,
        CURLOPT_UNRESTRICTED_AUTH => TRUE,
        CURLOPT_VERBOSE => TRUE,
        // Above options for debugging because I'm desperate
        CURLOPT_CONNECTTIMEOUT  => 30,
        CURLOPT_USERAGENT       => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
        CURLOPT_RETURNTRANSFER  => TRUE,
        CURLOPT_FOLLOWLOCATION  => TRUE,
        CURLOPT_POST            => TRUE,
        CURLOPT_POSTFIELDS      => $post_data
    ); 
    curl_setopt_array($ch, $opts); 

    //Capture result and close connection
    $result = curl_exec($ch);
    $debug  = curl_getinfo($ch);
    curl_close($ch);

There's nothing out of the ordinary in curl_getinfo except the expected ["ssl_verify_result"]=> int(0), which I'm ignoring for debugging. HTTP code is 200. If I echo $result, I can see that all form values are filled out, but the form never submitted and thus never redirected. If I then CLICK on submit, the form submits without issue and redirects as expected.

Again, this is not a problem with the first form, only the second. I'm guessing there's something about the underlying code on formstack that prevents cURL POST from submitting the form, but I can't seem to find it.

EDIT: I found the problem. There are two invisible elements on formstack forms. One of them is an input field called _submit which must be set to 1. The other is the form identifier, which is an integer.

Riley Laine
  • 181
  • 2
  • 11
  • Why do you run curl to the url of the form and not to the url of where the form is submitted to? – blablabla Mar 10 '16 at 14:48
  • your browser is using "multipart/form-data" encoding, while curl is using "application/x-www-form-urlencoded" encoding, BECAUSE you're using http_build_query. check the notes from http://php.net/manual/en/function.curl-setopt.php . some servers are sensitive to this. (PHP, by default, doesn't give a shit and decode both transparently to userland php code, though. thus, because PHP is super popular, most websites doesn't care, but those who isn't written in PHP might) – hanshenrik Mar 10 '16 at 20:01
  • It's a good idea, but I tried submitting it as just an array as well. No good. Apparently formstack has an API though. So I may just need to learn the API. – Riley Laine Mar 11 '16 at 06:58

0 Answers0