开发者

Removing form validation causes form not to submit?

开发者 https://www.devze.com 2023-04-11 11:03 出处:网络
I\'ve removed pretty much all .js references in my Magento theme. Specifically I\'ve removed theonclick from the add to cart button.

I've removed pretty much all .js references in my Magento theme. Specifically I've removed the onclick from the add to cart button.

in template/catalog/product/view/addtocart.phtml I've removed onclick="productAddToCartForm.submit(this)

in template/catalog/product/view/view.phtml I removed this block of code...

<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
    if (this.validator.validate()) {
        var form = this.form;
        var oldUrl = form.action;

        if (url) {
           form.action = url;
        }
        var e = null;
        try {
            this.form.submit();
        } catch (e) {
        }
        this.form.action = oldUrl;
        if (e) {
            throw e;
        }

        if (button && button != 'undefined') {
            button.disabled = true;
        }
    }
}.bind(productAddToCartForm);

productAddToCartForm.submitLight = function(button, url){
    if(this.validator) {
        var nv = Validation.methods;
        delete Validation.methods['required-entry'];
        delete Validation.methods['validate-one-required'];
        delete Validation.methods['validate-one-required-by-name'];
        if (this.validator.validate()) {
            if (url) {
                this.form.action = url;
            }
            this.form.submit();
        }
        Object.extend(Validation.methods, nv);
    }
}.bind(productAddToCartForm);
//]]>
</script>       

However, now when I submit the form I get nothing.

I figured to change the add to cart <button> to a proper submit. So I changed this....

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart"><span><span><?php echo $buttonTitle ?></span></span></button>

to this ...

 <input type="submit" value="<?php echo $buttonTitle ?>" />

When I do that, the form submits but I get a "Page Not Found", the URL it takes me to looks like this /checkout/cart/add/uenc/aHR0cDovLzcwLjMyLjc0LjQ2L3J0bF9tYWdlbnRvL2luZGV4LnBocC9jYXRhbG9nL3Byb2R1Y3Qvdmlldy9pZC8xNQ,,/produc开发者_Python百科t/15/

Is it not possible to submit a form the old fashioned way in Magento without javascript? If it is, can you give some pointers?

My plan was to hook up my own jQuery validation (which is quite simple, I just need to validate that the qty field has length) and ditch some of the ridiculousness of the code above.


I don't know how and I don't know why, but when I disable "Use Web Server Rewrites" it works with the standard submit button.

Removing form validation causes form not to submit?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号