Prestashop 处理自定义 CMS 表单中的帖子数据 [英] Prestashop Handle post data in custom CMS form

查看:42
本文介绍了Prestashop 处理自定义 CMS 表单中的帖子数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个显示表单的 prestashop 模块,现在我想使用 POST 数据将我的数据存储在数据库中.

I've developped a prestashop module that display a form, and now I want to use the POST data to store my data in the database.

按照一些教程,我可以显示表单并加载一些 js 文件,但我的问题有两个:

Following some tutorials I'm able to display the form and load some js file, but my question are two:

  • 我的表单的操作参数是什么?

  • What will be the action parameter of my form?

如何处理post参数,在哪里处理?

How can i handle the post parameters, and where??

我的模块的结构是这样的 - 根目录是/modules/mymodule/目录:

The structure of my module is this - root is /modules/mymodule/ dir:

  • mymodule.php

  • mymodule.php

/views/templates/hook/mymodule.tpl

/views/templates/hook/mymodule.tpl

/views/js/front.js

/views/js/front.js

我需要插入控制器吗??

Have i to insert a controller??

谢谢.

编辑 - 添加一些代码

mymodule.php

mymodule.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');
    }
}

mymodule.tpl

mymodule.tpl

<form id="myform" action="{$link->getModuleLink('mymodule', 'display')|escape:'html'}" method="post">
<!-- all fields...  + submit button -->
</form>

display.php(这应该是 mymodule/controllers/front 中的控制器)

display.php (this shoul be the controller in 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");


      }
    }

}

仅此而已……

推荐答案

请在下面找到您问题的答案:

Please find the answers to your questions below:

  • 我的表单的操作参数是什么?

表单的操作参数为

$this->smarty->assign('action', 'index.php?controller=AdminModules&token='.Tools::getAdminTokenLite('AdminModules').'&configure='.$this->name)

您需要在 getContent() 函数中将其从控制器 (mymodule.php) 分配给 smarty,然后您可以将其用作 TPL 文件中的操作.

You need to assign it to smarty from your controller (mymodule.php) in getContent() function and then you can use it as action in your TPL file.

  • 我如何处理 post 参数?在哪里?

您可以使用以下代码在 mymodule.php - getContent() 函数中获取帖子参数的值:

You can get the values of your post parameters in mymodule.php - getContent() function by using the following code:

$post_param = Tools::getValue('name_of_parameter');

这篇关于Prestashop 处理自定义 CMS 表单中的帖子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆