Jump to content

Using cURL to submit a form


pocobueno1388

Recommended Posts

I am able to successfully submit forms with cURL when there is a submit button, but recently I have ran into a problem.

 

I am trying to write code that will submit the form from this webpage:

http://www.attorneyssearchusa.com/submit.html

 

The problem is, the "submit listing" is not a submit button, it's just a button with no name.

<INPUT TYPE="button" VALUE="Submit Listing" ONCLICK="check(form,form.elements.length)" TITLE="Submit Listing">

 

So the question is, how do I tell cURL to hit the "submit listing" button?

 

Here is the code I have:

 

<?php
include '../config.php';

$query = mysql_query("SELECT * FROM locations");

while ($row = mysql_fetch_assoc($query)){

$curl_connection = curl_init('http://www.appealsattorneysusa.info/submit.html');

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

$post_data['name'] = 'Optimum HealthCare';
$post_data['addr'] = $row['street_addr']; //street address
$post_data['city'] = $row['city'];
$post_data['state'] = $row['state'];
$post_data['zip'] = $row['zip'];
$post_data['phone'] = $row['phone'];
$post_data['email'] = 'info@optimumhealthcare.org';
$post_data['web'] = 'http://www.optimumhealthcare.org'; //website
$post_data['comments'] = '';

foreach ( $post_data as $key => $value) {
	$post_items[] = $key . '=' . $value;
}

$post_string = implode ('&', $post_items);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

$result = curl_exec($curl_connection);
curl_close($curl_connection);

//print_r(curl_getinfo($curl_connection));
echo 'Success!<br>';


}

?>

 

Any Ideas? Thanks!

Link to comment
Share on other sites

Being as the form just submits back to the same page, if you pass the correct data the application should handle it as you expect. You don't ever tell cURL to "submit a form", you just send a request to the specified URL - or by that did you mean pass the submit button's name as data as well?

 

Whatever the case, you need to work out what data is required for the application to process the form. The JavaScript calls the .submit() method, so it's something relating to the actual inputs; have you spotted the hidden inputs at the top of the form?

 

I guess it's also possible they're also using some server side technique to prevent you making such a request.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.