删除表单验证会导致表单无法提交吗?
我已经删除了 Magento 主题中几乎所有 .js 引用。具体来说,我已从“添加到购物车”按钮中删除了 onclick。
删除了 onclick="productAddToCartForm.submit(this)
在 template/catalog/product/view/addtocart.phtml
中,我已在 template/catalog/product/view 中 /view.phtml
我删除了这段代码...
<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>
但是,现在当我提交表单时,我什么也没得到,
我想将添加到购物车
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart"><span><span><?php echo $buttonTitle ?></span></span></button>
到这个...
<input type="submit" value="<?php echo $buttonTitle ?>" />
当我这样做时,表单提交但我得到一个“页面未找到”,它带我去的URL看起来像这样/checkout/cart/add/uenc/aHR0cDovLzcwLjMyLjc0LjQ2L3J0bF9tYWdlbnRvL2luZGV4LnBocC9jYXRhbG9nL3Byb2R1Y3Qvdmlldy9pZC8xNQ,,/product/15/
是否无法提交旧的表单如果是的话,你能给出一些建议吗?
我的计划是连接我自己的 jQuery 验证(这很简单,我只需要验证 qty 字段的长度)并放弃一些上面的代码很荒谬。
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,,/product/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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道如何操作,也不知道为什么,但是当我禁用“使用 Web 服务器重写”时,它可以使用标准提交按钮。
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.