Magento形式post动作到自定义控制器不工作 - 错误的路由,但为什么? [英] Magento form post action to custom controller not working - wrong routing, but why?
问题描述
我在Magento商店有一个表格,联系表格。当我导航到表单时,它具有以下网址: http://www.domain123.com/contact/ 。有一个形式,它看起来像这样:
I have a form in my Magento store, the contact form. When I navigate to the form, it has this URL: http://www.domain123.com/contact/. There is a form and it looks like this:
<form id="contactForm" method="post" action="contactform/index/sendcontactmail">
...
</form>
现在,当我单击发送按钮,它给我一个404未找到,我知道为什么。它发布的网址是 http://www.domain123.com/contact/contactform/index/sendcontactmail ,这当然不是当然,它必须是 http:// www .domain123.com / contactform / index / sendcontactmail (无联系)。问题是,我如何解决这个问题?联系人表单作为姓名 和我的模块名称为 contactform 。我将如何解决这个问题?
Now, when I click the send button, it gives me a 404 not found and I know why. The URL it posts to is http://www.domain123.com/contact/contactform/index/sendcontactmail, which is not right of course, it has to be http://www.domain123.com/contactform/index/sendcontactmail (without contact). The question is, how do I solve this issue? The contact form as the frontname contact and my modules name is contactform. How would I solve this?
谢谢!
推荐答案
<form id="contactForm" method="post" action="/contactform/index/sendcontactmail">
或者如果使用.phtml模板,更安全的方法是使用一点PHP。这将插入正确的域:
Or if working from a .phtml template the safer way is to use a bit of PHP. This will insert the correct domain:
<form id="contactForm" method="post"
action="<?php echo $this->getUrl('contactform/index/sendcontactmail') ?>">
这篇关于Magento形式post动作到自定义控制器不工作 - 错误的路由,但为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!