0
<form action="http://www.website.com/add" method="post" target="_blank" >
    <select name="productid">
    <option value="84215_212">Size S</option>
    </select>
    <input type="hidden" value="1" name="xQuantity">

    <button class="button" type="submit"">
    <span>Add to bag</span>
    </button>

I would like to set my form above to send the request as "302 Moved Temporarily" instead of "200" after submitting which would then redirect to http://www.website.com/cart with GET request. How do I implement this? Thanks.

Stevens22
  • 11
  • 5

1 Answers1

1

Add the following at the top of the script handling /add:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // do something, then
    header('Location: /cart', true, 302);
    exit();
}
?>

I would like to set my form above to send the request as "302 Moved Temporarily" instead of "200"

Note, the code for "Moved Temporarily" is 301, not 302 (which is a code for "Found").

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
  • I don't have access to the files so I wouldn't be able to do this, I'm trying to simulate the script to another website. What method should I be using for this? – Stevens22 Dec 18 '16 at 16:00
  • @Stevens22, then you can implement a proxy script on your server which will forward requests to the remote site through cURL, for ex. This implies that you change the form's `action` to _your-server.com/add_. The latter forwards the submitted data to _website.com/add_. Then you read the response, make something with it, and perform the redirect as it is shown in the answer. The question as it is currently written does not reflect your real intentions, so I decided to drop this as a comment. – Ruslan Osmanov Dec 19 '16 at 03:30