Riley Laine
Riley Laine

Reputation: 181

PHP cURL filling out values form action is not fired

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.

Upvotes: 1

Views: 241

Answers (0)

Related Questions