Magento 2 -- debug.log -- main.调试:请求验证操作"VendorModuleControllerIndexPostInterceptor"失败



我正在实现一个自定义模块,该模块本质上具有与默认Magento 2联系表单相同的功能。我收到一个非常烦人的错误,我似乎找不到解决方案。似乎我的 POST 请求未能通过 Magento 的请求验证,但我不确定如何找到更具体的信息。

我试图实现一个绕过Magento CSRF验证的"CSRFSkip"插件。我尝试更改控制器扩展和实现的内容。我已经广泛搜索了日志。

这是我的Magento调试.log因为错误正在发生。

[2019-10-17 19:39:16] main.DEBUG: Request validation failed for action "VendorModuleControllerIndexPostInterceptor" [] []
[2019-10-17 19:41:20] main.DEBUG: Request validation failed for action "VendorModuleControllerIndexPostInterceptor" [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'catalog.compare.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'sale.reorder.sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []
[2019-10-17 19:41:21] main.INFO: Broken reference: the 'wishlist_sidebar' element cannot be added as child to 'sidebar.additional', because the latter doesn't exist [] []

这是我的控制器。/供应商/模块/控制器/索引/发布.php

<?php
namespace VendorModuleControllerIndex;
use MagentoFrameworkControllerResultFactory;
class Post extends MagentoFrameworkAppActionAction implements MagentoFrameworkAppActionHttpPostActionInterface
{
/**
* Post action
*
* @return void
*/
public function execute()
{
$post = $this->getRequest()->getPostValue();
if (!$post['name']) {
$this->_redirect('/find-a-dealer');
return;
}
$this->inlineTranslation->suspend();
try {
$postObject = new MagentoFrameworkDataObject();
$postObject->setData($post);
$error = false;
$this->logger->debug($post['name']);
if (!Zend_Validate::is(trim($post['name']), 'NotEmpty')) {
$error = true;
}
$this->logger->debug($post['email']);
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
$this->logger->debug($post['city']);
if (!Zend_Validate::is(trim($post['city']), 'NotEmpty')) {
$error = true;
}
$this->logger->debug($post['state']);
if (!Zend_Validate::is(trim($post['state']), 'NotEmpty')) {
$error = true;
}
$this->logger->debug($post['zip']);
if (!Zend_Validate::is(trim($post['zip']), 'NotEmpty')) {
$error = true;
}
$this->logger->debug($post['part']);
if (!Zend_Validate::is(trim($post['part']), 'NotEmpty')) {
$error = true;
}
if ($error) {
throw new Exception();
}
$storeScope = MagentoStoreModelScopeInterface::SCOPE_STORE;
$transport = $this->_transportBuilder
->setTemplateIdentifier($this->scopeConfig->getValue(self::XML_PATH_EMAIL_TEMPLATE, $storeScope))
->setTemplateOptions(
[
'area' => MagentoBackendAppAreaFrontNameResolver::AREA_CODE,
'store' => MagentoStoreModelStore::DEFAULT_STORE_ID,
]
)
->setTemplateVars(['data' => $postObject])
->setFrom($this->scopeConfig->getValue(self::XML_PATH_EMAIL_SENDER, $storeScope))
->addTo($this->scopeConfig->getValue(self::XML_PATH_EMAIL_RECIPIENT, $storeScope))
->setReplyTo($post['email'])
->getTransport();
$transport->sendMessage();
$this->inlineTranslation->resume();
$this->messageManager->addSuccess(
__('Thanks for contacting us with your comments and questions. We'll respond to you very soon.')
);
$this->getDataPersistor()->clear('find-a-dealer');
$this->_redirect('find-a-dealer');
return;
} catch (Exception $e) {
$this->inlineTranslation->resume();
$this->messageManager->addError(
__('We can't process your request right now. Sorry, that's all we know.')
);
$this->getDataPersistor()->set('find-a-dealer', $post);
$this->_redirect('find-a-dealer');
return;
}
}
/**
* Get Data Persistor
*
* @return DataPersistorInterface
*/
private function getDataPersistor()
{
if ($this->dataPersistor === null) {
$this->dataPersistor = ObjectManager::getInstance()
->get(DataPersistorInterface::class);
}
return $this->dataPersistor;
}
}

我希望我的帖子功能能够运行并发送我的电子邮件。

实际发生的是重定向到我的表单页面,以及日志中的一些与验证相关的错误。

不要直接从浏览器调用 url。 将其添加到菜单操作链接或按钮,然后从那里调用它。

禁用管理员中的密钥并尝试。

就我而言,这是form_key。我已经明确添加了表单键输入字段,它解决了这个问题。

你能检查var,生成和pub文件夹的权限吗?使用 root 用户部署更改时,权限可能会更改为 644,从而导致这些类型的问题。

最新更新