我对定制表单有问题,它应该向自定义控制器发出post请求,它将我重定向到搜索页面,我不知道为什么。当我试图将动作url粘贴到浏览器中时,它就可以正常工作了。
我的表格phtml:
<form class="quick-order-list"
method="post"
action="<?php echo $block->getFormAction(); ?>"
name="listsform"
enctype='multipart/form-data'>
<?= $block->getChildHtml('quick_order_multipleskus') ?>
<?= $block->getChildHtml('quick_order_file') ?>
<div class="quick-order-list-button">
<div class="secondary">
<button type="submit"
name="lists"
title="<?= __('Add to List') ?>"
class="action submit primary">
<span><?= __('Add to List') ?></span>
</button>
</div>
</div>获得行动方法:
public function getFormAction()
{
return $this->getUrl('quickorder/lists/index', ['_secure' => true]);
}控制器位于vendor\module\Controller\Lists\Index.php文件中。
<?php
declare(strict_types=1);
namespace module\vendor\Controller\Lists;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Controller\Result\Forward;
use Magento\Framework\Controller\Result\ForwardFactory;
class Index implements HttpGetActionInterface
{
private $forwardFactory;
public function __construct(
ForwardFactory $forwardFactory
) {
$this->forwardFactory = $forwardFactory;
}
public function execute()
{
die('ello');
}
}在html中,对我来说,它看起来没问题:
<form class="quick-order-list" method="post" action="http://pleasehelp.local/quickorder/lists/index/" name="listsform" enctype="multipart/form-data">按下提交后,我将登陆:/catalogsearch/result/?q=quickorder+lists+index
Magento 2.4.0,php7.3
它甚至没有在execute函数中登陆,但是当我将die()放在它工作的地方时,我可以在构造函数中捕获它。尝试过很多人认为,从表单中移除字段,试图指向其他控制器,将静态操作url放在那里,
为了让它正常工作..。
我开始怀疑它与我的代码无关,但是在项目中有些东西坏了,但是不知道如何检查它,有人能指出正确的方向吗?
发布于 2020-11-10 06:53:40
您应该在控制器类中实现Magento\Framework\App\Action\HttpPostActionInterface而不是HttpGetActionInterface。
https://stackoverflow.com/questions/64728932
复制相似问题