pocobueno1388 Posted June 30, 2010 Share Posted June 30, 2010 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'] = '[email protected]'; $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! Quote Link to comment https://forums.phpfreaks.com/topic/206297-using-curl-to-submit-a-form/ Share on other sites More sharing options...
Adam Posted June 30, 2010 Share Posted June 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206297-using-curl-to-submit-a-form/#findComment-1079247 Share on other sites More sharing options...
pocobueno1388 Posted June 30, 2010 Author Share Posted June 30, 2010 Thanks, I'll test that and see if it works. Quote Link to comment https://forums.phpfreaks.com/topic/206297-using-curl-to-submit-a-form/#findComment-1079282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.