Forum Moderators: buckworks

Message Too Old, No Replies

Shopping Cart Validation Question

validating submit buttons

         

Sangarius

4:55 pm on Apr 8, 2004 (gmt 0)

10+ Year Member



Hello,

I am creating a web based application (ASP, JScript, SQL) that has order placing functionality. I am trying to make a database driven shopping cart to achieve this (first attempt). My problem is I have multiple submit buttons "add to cart" - one per item. Because I am pulling my product id from the database I have set up a loop in which to print my product description, a quantity field, and of course the submit button until the end of the recordset has been reached. I am passing the product id and quantity, then setting up an array to sort those values on the next page, that is fine. However, it will take me over to the next page no matter which "add to cart" button I press. How can I validate this and ensure that my quantity is not 0 for the corresponding button? I need to find a way to uniquely identify each submit button within that loop, so I can successfully validate before passing the information. Any suggestion? Your help is very much appreciated.

Sangarius

PCInk

5:24 pm on Apr 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...if the quantity is zero, then the user has probably made a mistake. There are two options I would use:

1) Warn the customer in the basket page:

if($qty < 1)
{ print "<p>Your quantity of '$qty' is invalid. We have added one into the basket for you</p>"; $qty = 1; }

or 2) Show a completely different page that requests the quantity:

if($qty < 1)
{ &get_quantity_page_sub_routine; exit; }

where the routine get_quantity_page_sub_routine shows a box for them to correct their quantities.

The method I would use would depend on the selling product. If the customer is likely to order more than one of an item I would recommend the second. If most customers will only order one of each line, use option 1 (i.e. correct the error for them).

Sangarius

5:36 pm on Apr 8, 2004 (gmt 0)

10+ Year Member



I have my site designed in a way that the user will never be able to order more items than they are entitled (uniform orders). Therefore I have my quantities in a select control drop down box. The values in each of these boxes is defaulted to 0. So when I pass my quantities over to the next page it recieves a string like 0,0,0,1,0. I then load these values into an array. Now that this is clear, my question still remains. I need to identify which submit button has been pressed and if the corresponding quantity has a value other than 0. If quantity is 0 then the user will have an alert box displayed. If I am still unclear on any part, please let me know and I will try to explain to the best of my ability as I need this problem solved.

Thank you,
Sangarius

raywood

1:56 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



Couldn't you just use client side javascript behind the buttons and send a hidden field to tell you which one was clicked?

ray

bmcgee

7:06 pm on Apr 10, 2004 (gmt 0)

10+ Year Member



Not all users have JavaScript turned on. Providing a solution which does not work for those users can result in lost sales.

Ideally, it is best to implement validation client side with javascript, for those that have it enabled. Then also perform it server side to catch the non-JS situations.