server validation
Hi all,
i just did this another way and was interested in the outcome of this thread.
I didn't use server validation, (this time), I assume I would need CSS form builder to do this ??
Anyway here's my approach, no server side validation required.
Having retrieved my stock value from the appropriate recordset, in the block of code beginning near // WA eCart AddToCart...
After the first line checking that the form has been submitted. add a new 'if' block, something like this, where Cartname is the name of your cart.
Also add a line, setting a variable to false just before this block, (existing code is shown in grey)...
$stockwarning = false;// resets the stock warning message to false
// WA eCart AddToCart
if (isset($_POST["Cartname_1_ATC"]) || isset($_POST["Cartname_1_ATC_x"])) {
if($row_rsStockLookup['StockQty'] < $_POST["rugsntack_1_Quantity_Add"]) { ) {//row from recordset value compared to qty entered into add to cart form
$stockwarning = true;
}
else
{//do the cart code
$ATC_itemID = $_POST["Cartname_1_ID_Add"];...
You also need to add an extra closing bracket at the end of this block, about 25 lines down.
When the 'add to cart' form is posted, if the stock level is below the item quantity value, the $nostock variable is set to true, and the add to cart code is not processed, hence the page is not redirected.
You can then show a message somewhere on your page, such as
<?php if ($stockwarning == true) {
echo 'Message to customer';
} ?>