I'm trying to add form validation on the category view and to show error message on the category page.

Currently, if there's an error it will redirect you to the product view page and display the error.

For example, if you try to add more Qty of a product than is available from the category view, it will redirect you to the product view with the following error message:

The requested quantity for "X Product" is not available.

How would I perform this validation and display error message on the Category view without redirecting to Product view?

Here is my current code in list.phtml to add product to cart:

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
    <span class="qty-input"><input type="number" class="required-entry" name="qty" id="qty" value="1" min="1" max="<?php echo $stock ?>" /></span>
    <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button medium primary" onclick="this.form.submit()">Add to Cart</button>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.