Jump to content

shopping cart validation


chet139

Recommended Posts

I know its a bit of javascript to but its relevant to php aswell.

 

function checkolineFields() //validation
	{
		if(oline.id.value.length >=1 && oline.qty.value.length >=1) 
		{
			return true;
		}


		else 
		{
		alert("Please provide the required data");
		return false;
		}
	}

 

I use this code to ensure both fields are filled in. ands it works so when submitting empty fields to cart - it wont let it happen. But once the cart has one item inside it and i go back to the form where the user can enter productID the validation seems to stop work any idea why. heres the other bit of relevent cod (perhaps)

 

echo'

<form name="oline" action="cart.php" onsubmit="return checkolineFields(this)" method="get">
	<input type="hidden" name="action" value="add_item" />
	<b>Product ID:</b> <br/><input type="text" name="id" size="9" maxlength="9" onKeyPress="return numbersonly(this, event)"  /><br/> 
	<b>Quantity:</b> <br/>
	<input type="text" name="qty" value="1" size="4" maxlength="4" onKeyPress="return numbersonly(this, event)" /><br/>
	<input type="hidden" name="orderId" value=" '. $orderId . '" />
	<br/>
	<input type="submit" value="Add to Order" />
</form>

Link to comment
https://forums.phpfreaks.com/topic/102469-shopping-cart-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.