Link to home
Start Free TrialLog in
Avatar of will4062
will4062

asked on

How to do a HTTP (check) query string redirect?

We are trying to make a redirect on our site based on the following scenario:

On the main page of a shopping cart, the user picks from 2 categories.  After picking a category, the user picks accessories to go with that product.

Upon picking THE CATEGORY, we want the main product for that category to automatically add to their cart, and then proceed to the accessories page.

The problem is, it HAS to goto the view cart page upon adding the main category product.. So we want it to redirect the user to the accessory page based on the previous location that they came from.

We want to add a query string, where it would tell which product category is picked from the main page.

On the cart page that it redirects to when you click one of the categories, we want it to see that if the category selected equals 1 or 2, then it redirects to the next page in the process for that category
Avatar of Tintin
Tintin

I'd just add a hidden field with category and then the view cart page simply has to see what value is in the category field and redirect to the appropriate page based on the number.
Avatar of will4062

ASKER

Example?
This is what I want to do to clarify it:

Main Page --> Choose Item 1 or 2
Item 1 ----> shopping cart (redirect to cart on click)
Item 2 ----> shopping cart (redirect to cart on click)
Shopping Cart ----> Item 1 pages (redirects to item 2 pages based on previous url)
Shopping Cart ----> Item 2 pages (redirects to item 2 pages based on previous url)
a bit confusing to me, somehow ...
Could you please explain what you mean by redirect?

Anyway, assuming following:
  1. maiin page /main.cgi:
     user chose item 1 and wants the accessories, therfore in the main page are following links:
     <a href="/.cgi?item=1">1. accessories</a>
     <a href="/accessories.cgi?item=2">2. accessories</a>
 2. accessories page /accessories.cgi:
    contains a form for your accessories, like:
    <form name="accessories" action="/main.cgi">
       <input type="hidden" name="category" value="1" />
             <!-- above inserted by your accessories.cgi from its parameter item= -->
       <input name="a1" .... />
       <input name="a2" .... />
       <input type="submit"  />
  3. main page again which was produced by main.cgi:
Sorry, it sounds like you understood it a bit wrong

Basically, the user goes through a "building block" process, where they pick one required item on the main page (which is automatically added to the cart), then they goto a list of accessories that are available only for that item (which are on a seperate page than the main page).

However, after they pick the required item on the main page, they are redirected to the shopping cart. It has to work like this because of our cart system. So, we want it to redirect back to the accessories page from the cart based on which required item they selected.

This is what I have tried on the required item page:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>
             
<input type=hidden name=storeid value=*107a534098078ee10e04>
<input type=hidden name=dbname value=products>
<input type=hidden name=function value=add>
<input type=hidden name=itemnum value=2>

<input type=image class="add" src="http://test.com/store/media/straight.gif" name="Add to Cart" value=2 alt="Add to Cart">

</form>

But, it doesnt work because it wont add the required item value to the url
> But, it doesnt work because it wont add the required item value to the url
for post method the parameters are not added to the URL, but send as body in the HTTP request
You either have to parse the POST parameters, or change the form to method=get
The storeid adds to the URL fine
and the others add too, separated by &
otherwise you have a buggy browser
>> This is what I have tried on the required item page:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>
             
<input type=hidden name=storeid value=*107a534098078ee10e04>
<input type=hidden name=dbname value=products>
<input type=hidden name=function value=add>
<input type=hidden name=itemnum value=2>

<input type=image class="add" src="http://test.com/store/media/straight.gif" name="Add to Cart" value=2 alt="Add to Cart">

</form>

change this line:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=post>

to:

<form action="http://www.test.com/cgi-bin/sc/order.cgi" method=get>

Perl_Diver, did you read my comments?
if the method is post, nothing gets added to the URL (except by buggy browsers)
if the method is get, all gets added to the URL (except by buggy browsers)
( and I also do not see any malware, like JavaScript, ActiveX, which might do it)
;-)
I skimmed through the thread so if I missed something my apologies.
no worries, we all have bad days ... ;-)
What language is order.cgi written in?  Do you have to rely on GET methods?  There's generally not much need to use them.
I actually figured it out using cookies and if -else statements. Ill post how I did it if anyone is interested
using cookies or hidden form fields is rather the same, except that hidden form fields work with any browser while cookies depend on the user's browser configuration
Please post the solution as the question was pretty generic, so it was a little hard to help without more detailed information.
Here is just everything I have on the cart page:

<script>
if (document.referrer=="http://snaphitch.com/store/product7.html")
{
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else if (document.referrer=="http://snaphitch.com/store/product8.html")
{
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
</script>
<script>
var adjusted = document.cookie.split("/adjustable.gif");
if(adjusted.length>1)
{
  adjusted = adjusted[1].split("/")[0];
  alert ("The Adjustable Snap Hitch was added to your cart. Now choose a drop shank required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/page4.html";
}
else
{
  adjusted="";
}
</script>
<script>
var straight = document.cookie.split("/straight.gif");
if(straight.length>1)
{
  straight = straight[1].split("/")[0];
  alert ("The Straight Snap Hitch was added to your cart. Now choose a kingpin ball assembly to match your trailer's coupler.")
  window.location ="http://www.snaphitch.com/store/page3.html";
}
else
{
  straight="";
}
</script>

<script>
var shank1 = document.cookie.split(":QH-13");
var shank2 = document.cookie.split(":QH-13L");
if(document.referrer=="http://www.snaphitch.com/store/page4.html" && shank1.length>1)
{
  shank1 = shank1[1].split(":")[0];
  alert ("The shank was added to your cart. Now choose a kingpin required for proper operation of the Adjustable Snap Hitch.")
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else
{
  shank1="";
}
if(document.referrer=="http://www.snaphitch.com/store/page4.html" && shank2.length>1)
{
  shank2 = shank2[1].split(":")[0];
  window.location ="http://www.snaphitch.com/store/kingpin.html";
}
else
{
  shank2="";
}
</script>

<script>
if(document.referrer=="http://www.snaphitch.com/store/page3.html"  || document.referrer=="http://www.snaphitch.com/store/kingpin.html" || document.referrer=="http://snaphitch.com/store/product3.html" || document.referrer=="http://snaphitch.com/store/product4.html" || document.referrer=="http://snaphitch.com/store/product5.html" || document.referrer=="http://snaphitch.com/store/product6.html")
{
  alert ("Congratulations, you've successfully built your Snap Hitch!")
}
</script>


And on the individual pages:

<script>
var redirs = document.cookie.split("/straight.gif");
if(redirs.length>1)
{
  redirs = redirs[1].split("/")[0];
  window.location ="http://www.snaphitch.com/store/page3.html";
}
else
{
  redirs="";
}
</script>
<script>
var redirss = document.cookie.split("/order.cgi");
if(redirss.length>1)
{
  redirss = redirss[1].split("/")[0];
  window.location ="http://www.snaphitch.com/cgi-bin/sc/order.cgi?storeid=*107a524308078e910ed1&function=show";
}
else
{
  redirss="";
}
</script>
ASKER CERTIFIED SOLUTION
Avatar of CetusMOD
CetusMOD
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial