Fill external form with cURL

I'm trying to fill and submit an external form using cURL, but actually I can't fill the field and I would understand why.

How can I see the filled form, immediately after the form submission?

I have the following code:

    <?php

         //create array of data to be posted
           $post_data['fname'] = 'Mario';
           $post_data['lname'] = 'Rossi';
           $post_data['email'] = 'mario@rossi.it';
           $post_data['memberid'] = '1010101010';
           $post_data['mobile'] = '3456789';


         //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('http://dennehys.ie/mobile/douglas/formview.php?qstr=dHlwbz0mZGF5PVR1ZXNkYXkmZGF5ZGF0ZT0yMDE2LTAxLTI2JnJuZD0mY2xhc3NzaGVkdWxlPTQ5Mw==');

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

          //set data to be posted
          curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

          //perform our request
          $result = curl_exec($curl_connection);
          print_r($post_data);
          echo $result;

          //show information regarding the request

          print_r(curl_getinfo($curl_connection));
          echo curl_errno($curl_connection) . '-' . 
            curl_error($curl_connection);

         //close the connection
          curl_close($curl_connection);

     ?>

Answers


Looking at the page you are posting to, the form has the following line:

<form action="formresponse.php" method="post" data-ajax="false" name="book">

This implies that you are posting data to the wrong page, as all the posted data from that form goes to formresponse.php. It's likely that the page you're sending to doesn't do anything with the data you're posting.

Try changing this line:

curl_init('http://dennehys.ie/mobile/douglas/formview.php?qstr=dHlwbz0mZGF5PVR1ZXNkYXkmZGF5ZGF0ZT0yMDE2LTAxLTI2JnJuZD0mY2xhc3NzaGVkdWxlPTQ5Mw==');

to:

curl_init('http://dennehys.ie/mobile/douglas/formresponse.php');

I changed the line and I fixed my code, because there were four hidden input type, now the code looks working but I'm not really sure.

The hidden inputs type are:

'typo' an empty field (I think that field is empty)

'day' = 'wednesday'; (the day when you want book the class)

'clsdl' = '485'; (class ID)

'daydate' = '2016-01-27'; (date of the class)

When I send the request the code answers me with a success message.

Now I can't understand how I can send a request to book a class at specific time.

What I mean is, Is possibile to have two classes of the same sport in the same day and I want to specify the class that I want book.

I tried to read the source code of the page but I can't understand how can I do that.


Need Your Help

Import a database using AzureRM Powershell

azure azure-powershell azure-resource-manager azure-sql-database

There is a document named Import a BACPAC file to create a new Azure SQL database using PowerShell that covers how to import a bacpac file into SQL server under ASM.

apache proxy to tomcat keep alive confusion

apache tomcat ajp keep-alive

I have an apache 2.2 server infront of a tomcat 6 server. using mod_proxy_ajp on apache to proxy requests to tomcat. pretty standard setup.