is it possible to redirect user bk to the previous page with the POST value set

Hi ,

I have a form that is a simple drop down giving the user options of a wine type and region for example “red wine” and “spain” , once the submit button has been pressed it then sends the information to the products page where a query is ran from the user input from the form and the products are displayed , once the product is displayed there is a “add to cart” button under each item , what i want to do is once the add to cart button is pressed it will add the item into the cart(this works) and then redirect them back to the products page they were previously on with the values still set so e.g. “red wine” and “spain” , ive tryed using $_SERVER[‘HTTP_REFERER’] but it just redirects to the products page with no POST values set ,

Any help would be great thanks

There are a few ways to do it, if “add to cart” is form you can use hidden inputs to replace the post data have the form direct to itself rather than another page and include the form handling at the beginning pending a submit check.

If you are using a header redirect you could send the variables through the URL ie: products.php?item=variable1&type=variable2 you would just get the items with _GET rather than post

Hope this makes sense and helps I’m trying to type on a difficult device.

I personally save form input into sesson variables if an error occurs or the user may otherwise need to reuse the input. I then echo that session variable into the value of the form field.

Thank you both for your advice , I’m going to try the session option as the guy I’m building the site for asked that the url stays clean (not even url re write )otherwise I would us get , thanks again

Sponsor our Newsletter | Privacy Policy | Terms of Service