【发布时间】:2023-04-07 03:18:02
【问题描述】:
我开发了一个显示表单的 prestashop 模块,现在我想使用 POST 数据将我的数据存储在数据库中。
按照一些教程,我可以显示表单并加载一些 js 文件,但我的问题是两个:
我的表单的操作参数是什么?
如何处理 post 参数,在哪里处理?
我的模块的结构是这样的 - 根是 /modules/mymodule/ dir:
mymodule.php
/views/templates/hook/mymodule.tpl
/views/js/front.js
我要插入控制器吗?
谢谢。
编辑-添加一些代码
我的模块.php
class MyModule extends Module
{
public function __construct()
{
$this->name = 'mymodule';
$this->controllers = array( 'display' ); // <- my controller name
parent::__construct();
}
public function install()
{
if (Shop::isFeatureActive())
Shop::setContext(Shop::CONTEXT_ALL);
if (!parent::install() ||
!$this->registerHook('customCMS') ||
!$this->registerHook('header')
)
return false;
return true;
}
public function hookcustomCMS($params)
{
if (Tools::getValue('id_cms') != 7)
return;
$this->context->smarty->assign(
array(
'form_link' => $this->context->link->getModuleLink('mymodule', 'display')
)
);
return $this->display(__FILE__, 'mymodule.tpl');
}
}
我的模块.tpl
<form id="myform" action="{$link->getModuleLink('mymodule', 'display')|escape:'html'}" method="post">
<!-- all fields... + submit button -->
</form>
display.php(应该是mymodule/controllers/front中的控制器)
<?php
class mymoduledisaplyFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();
$this->context->controller->addJS($this->module->getLocalPath().'views/js/front.js');
$this->setTemplate('mymodule.tpl');
}
public function postProcess()
{
if (Tools::isSubmit('submit_requestform'))
{
// form processing
ppp("OK");
}
}
}
就是这样……
【问题讨论】:
-
这个表格是什么?模块配置?首页?管理页面?如果是首页或管理页面,是的,您需要一个控制器。您还需要提供更多信息和一些代码,以便我们进一步帮助您。
-
@TheDrot 我已经编辑了添加我的代码的帖子。应该是前端控制器。我的范围是添加一个包含一些字段和逻辑的表单,并将数据存储在数据库中。我省略了一些无用的代码,例如配置。
-
控制器的类声明错误。查看here 进行正确声明。
-
@TheDrot 解决了调用流程。不是我可以继续我的发展!谢谢!
标签: php prestashop prestashop-1.6