2

I want to send the POST data to the given external url like http://www.example.com/catchPostData.php, where the catchPostData.php looks like this:

<?php
echo $_POST['somedata'];
?>

and open this url with the data I've send.

I've tryed to use cURL, but it returns from the given url, and I want to stay there!

Can anybody help me with this?

bbbb
  • 141
  • 2
  • 3
  • 11

3 Answers3

1

I think you're looking for something like this: PHP Redirect with POST data

You will need a second page, that submits the post data to a completely different url.

Community
  • 1
  • 1
Wesley Overdijk
  • 1,176
  • 10
  • 18
-2

You will need two pages: one page for the input, the second page which redirects the input to an external url. as such your code would look like this:

page1:

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

<input type="hidden" name="somedata" value="yourData">

<input type="submit" name="submit" />

</form>


page2:
//you can create an array contains your posted data
//if you are dealing with multiple values
$array = array("somedata"=>$_POST['somedata']);

//create a url variable that will store all values
//since you are going to send them as part of a single url 
$url="";

//if you are posting more than one value you will need to loop
//through each one - not necessary if you are sending a single value

foreach($array as $key=>$value){

    $url .=$key."=".urlencode($value)."&";
}

header("http://www.example.com/catchPostData.php?$url");
awsmketchup
  • 112
  • 2
  • 14
  • Thank you for your answer, but everything goes like this: 1. the button is clicked on the first page -> button execute function where needed data are gathered -> the data are sent without any form by POST -> the external page catches the data and uses them to fill some fields – bbbb Aug 01 '13 at 14:04
  • its okay...happy to help – awsmketchup Aug 01 '13 at 14:07
-4

You can use with document.ready function

$.post({
         url: "you_page.php",
         type: "POST",
         data:{formId:form_id},
         success: function (data){
         }
 });
Nisarg
  • 3,024
  • 5
  • 32
  • 54