Alright.. this seems simple but I can't figure it out.
I made a <form> that uses POST into an external URL.. but how would i make it so that i can POST directly into the URL?
this is my system: When a user on my site completes an offer, it goes to my Postback URL and inserts it into my sql database.. then I want it to take those same values I used to insert into my SQL to POST it into an external website. I have all the values for the POST, I just need to know how to be able to post into that site automatically without the use of a button so it can just do everything automatically.
I am drawing a complete blank. Can i send a POST without a form?
Last edited by markman641; 02-01-2012 at 02:45 AM..
Alright.. this seems simple but I can't figure it out.
I made a <form> that uses POST into an external URL.. but how would i make it so that i can POST directly into the URL?
this is my system: it calls on a script to do a bunch of SQL tasks, then at the end of that it takes the values and uses POST into the URL... how would I make it automatically POST without having to use an ok/send/submit button?
I am drawing a complete blank. Can i send a POST without a form?
Wrong forum btw
To answer, POST is just a method of passing values. Using a form is the most common method, but you can send POST data several other ways - via AJAX or PHP libraries (cURL as one). Which one you choose is up to you.
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
To answer, POST is just a method of passing values. Using a form is the most common method, but you can send POST data several other ways - via AJAX or PHP libraries (cURL as one). Which one you choose is up to you.
Sounds like AJAX is probably your best bet.
I'm glad that made sense to you. I updated the OP to make a little more sense. Ill look up on google how to do AJAX. Could this be added to my postback script so it wont take it off the page?
Last edited by markman641; 02-01-2012 at 02:49 AM..
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
//url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&');
//open connection $ch = curl_init();
//set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post $result = curl_exec($ch);
//close connection curl_close($ch);
?>
Last edited by markman641; 02-01-2012 at 03:47 AM..
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
?>
What do you mean? Is it giving you any error? You should check for a false $result, then do something with curl_error($ch).
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Did you check for a false $result, and then echo (or kill the script with die(curl_error($ch))) curl_error($ch)? That will, like mysql_error(), hold the error message from the cURL transaction if there was one - PHP will not report it implicitly.
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Did you check for a false $result, and then echo (or kill the script with die(curl_error($ch))) curl_error($ch)? That will, like mysql_error(), hold the error message from the cURL transaction if there was one - PHP will not report it implicitly.
Like I said i have no clue about any of this -.- I'm sorry i just dont understand.
It seems like it would be SO easy just to POST to an external URL with my values without a form.
could i just make it go to the form page, fill the values using get and have an autosubmit form?
i really dont know i cant think straight :P
Last edited by markman641; 02-01-2012 at 04:32 AM..
Like I said i have no clue about any of this -.- I'm sorry i just dont understand.
It seems like it would be SO easy just to POST to an external URL with my values without a form.
could i just make it go to the form page, fill the values using get and have an autosubmit form?
i really dont know i cant think straight :P
Lol, you just need to read what I'm saying properly . I'm asking you to put some error reporting in, so we can see what's going wrong.
PHP Code:
Rest of your code up to this point
//execute post
$result = curl_exec($ch);
// Do some error reporting. $result will be FALSE if curl_exec() failed for some reason
if(!$result){
echo 'cURL Error: '.curl_error($ch);
}
// Replace this
if(isset($_POST['submitButton']))
// With this
if(!empty($_POST))
// Then check for values/forms. Some IE versions don't send the submit button
Quote:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.