PHP Redirect with POST data

后端 未结 13 1612
不思量自难忘°
不思量自难忘° 2020-11-22 06:22

I did some research on this topic, and there are some experts who have said that it is not possible, so I would like to ask for an alternative solution.

My situation

13条回答
  •  野性不改
    2020-11-22 07:15

    I have another solution that makes this possible. It requires the client be running Javascript (which I think is a fair requirement these days).

    Simply use an AJAX request on Page A to go and generate your invoice number and customer details in the background (your previous Page B), then once the request gets returned successfully with the correct information - simply complete the form submission over to your payment gateway (Page C).

    This will achieve your result of the user only clicking one button and proceeding to the payment gateway. Below is some pseudocode

    HTML:

    JS (using jQuery for convenience but trivial to make pure Javascript):

    $('#submitButton').click(function(e) {
      e.preventDefault(); //This will prevent form from submitting
    
      //Do some stuff like build a list of things being purchased and customer details
    
      $.getJSON('setupOrder.php', {listOfProducts: products, customerDetails: details }, function(data) {
      if (!data.error) {
        $('#paymentForm #customInvoiceID').val(data.id);
        $('#paymentForm').submit();   //Send client to the payment processor
      }
    });
    

提交回复
热议问题