Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to create a form on my page to get information this is easily done and the problem.

I want to 'POST' information to my own php-page, creating a new id and saving the information to my database. And then this page should redirect to the external page via 'POST' with id, price and so on.

The external page is a page to pay, so the customer should get this external site and should be able to use it like a normal page(maybe target="_blank").

In Short:

  1. Customer provides information such as item to buy, purchase amount, shipping address etc.

  2. Information will be saved into the database and will need to generate a new customer id.

  3. Page redirects to external payment page, sending id, price, payment information via 'POST'.

My problem is, how to redirect to the external page but sending custom information via 'POST'.

share|improve this question

2 Answers 2

You can actually submit any form via POST to any page (even if it resides on a remote server). So as long as you specify the URL to the CGI page (PHP, PERL, Python), it should work.

In PHP, you can send header information (and therefore redirects) to any page on the local or a remote server, and have that happen after the form is submitted.

Of course in the example below, things are generalized. You'd want to add some qualifiers for "if form had an error" or "if unable to submit data" then don't send user to the new page. But hopefully the concepts prove helpful.

<?php
$target = 'path-to-post-processor.php'; //leave blank to submit to self
if(isset($_POST['submit']))
{
    header('Location: http://example.com/other/page.html');
}
?>
<!--submit form via POST-->
<form action="<?php echo $target;?>" method="post">
<input name="something" type="text" maxlength="12" />
<input name="submit" type="submit" />
</form>

I'm also assuming you've got the database set up already. If you are still having trouble, add more details to your question (what have you tried, what are the errors) and we can go from there.

share|improve this answer
    
I tried it but the remote script didn't get my input. That's what I want –  robin591 Mar 21 '13 at 21:34

You could opt to use a cookie method since if they refresh the page they could lose the post data.

For example:

  1. Customer fills in address information and other details that is then saved into the MySQL database and is assigned a unique customer ID. This id is then saved as a cookie on the customers machine - Once cookie has been saved you then forward them to the next page which is the payment page.

  2. On the payment page you then retrieve SQL data based on customer ID held in Cookie.

Another way is no redirecting and use a Ajax solution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.