tags:

views:

49

answers:

2

Hi, I'm trying a basic thing. I have two files: curl.php and form.php

curl.php

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/test/test34_curl_post/form.php");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'nabc' => 'fafafa'
));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>   

form.php

<form action="form.php" method="post">

<input type="hidden" name="nabc" value="abc" />
<input type="submit" name="submit" value="Send" />

</form>


<?php

if(isset($_POST['submit']))
{
 echo '<br />Form sent!'.$_POST['nabc'];
}
?>

what I'm hoping to get is as the result of running curl.php, to see "Form sent!". It seems as if it wasn't sent as POST. In firebug (network) there is only one GET request and what I get is the form, nothing sent. Anyone, please help.

A: 

You need to change the action of your form to "curl.php" if you're trying to have that script process your form.

Brian Driscoll
`'form.php'` handles form submission. `'curl.php'` is just submitting to it.
rojoca
ah, of course... I should have taken a closer look at the PHP script since it's clear when I look at it now.
Brian Driscoll
+1  A: 

You're not sending 'submit' in your POST data so isset($_POST['submit']) will be false. You need to do the following:

curl_setopt($ch, CURLOPT_POSTFIELDS, array(
    'nabc' => 'fafafa',
    'submit' => 'Send' // if you want 'submit' in $_POST you need this
));
rojoca
that did the trick, thanks!
Pawel
Btw: maybe you know how to do that when there is:<form onsubmit="document.form1.submit();" name="form1" method="post" action="process.php">
Pawel
`onsubmit="document.form1.submit()"` is pointless because the only way it could be triggered is by submitting `form1`. I think it's best if you submit another question with the details.
rojoca
just to give you the idea, i don't know if it's enough for another question:http://web.copart.com/cgi-bin/counter/login.dtw/disp
Pawel
Just add `<input type="hidden" name="submit" value="Send"/>` to the form - get rid of `onsubmit="...`
rojoca
I only provide the form with data. I'm trying to log in and get a cookie.
Pawel