Skip to content Skip to sidebar Skip to footer

How To Do Two POST Requests For Visitors With JS Disabled On One Submit Button?

I got help with solving a problem in this thead: Redirect with POST data. Now that I decided that the whole site and even this function must work when JS is disabled I need to get

Solution 1:

If you want to make the browser to re-send the data of a HTTP Post request to another URI, the HTTP/1.1 protocol offers the 307 (temporary redirect) response status code to signal such to the HTTP-client (Browser):

header('HTTP/1.0 307 Temporary Redirect',$replace=true,307);
header('Location: some_new_url_here');

Read the specs carefully and see the notes on the 302 status as well.

It's much more useful to handle the payment over an API on server-side instead of risking a user being irritated by additional messages displayed by the browser where the user must actually decide whether or not the additional redirect is to be performed.


Solution 2:

Use CURL extension to post request to payment server when processing your user's request on server-side.

If your user must be redirected to some external web site, than save needed data first and then redirect him using header() function. Keep in mind that in this case you wouldn't be able to use POST method for making request to remote payment server.


Solution 3:

A redirection with HTTP Location would have your user end on another site. I suggest you trigger an HTTP-request from your server using curl or streams.


Solution 4:

The reason they initially suggested AJAX is for user experience, and is not a requirement for a form to be able to post. You will need to either present the user with a separate step to choose a form or have the same page reload or load another page.

Some pseudocode for example:

<?php
   if (!isset($_POST['form_type']) { 
       display_form_selection();
   } else {
       switch ($_GET['form_type']) {
           case 'credit_card': display_form('credit_card');
                   exit;
           case 'cash': display_form('cash');
                   exit;
           default: display_form_selection(); 
                    die()
       }
   }

Your form_selection() routine should draw a form which has a select, checkbox, radio button or whatever that will POST a string or integer (for the switch) back to the script you are running from.

When the page reloads it will call the correct display_form() based on the value it passed to itself. These functions will set up the form for whatever you want to post to the gateway.

I have read elsewhere on this site that using for your form action is not a good idea, and you should rather manually type your script name in.


Post a Comment for "How To Do Two POST Requests For Visitors With JS Disabled On One Submit Button?"