【问题标题】:Prestashop smarty make a form for user and save the input fields to the database?Prestashop smarty 为用户制作表单并将输入字段保存到数据库中?
【发布时间】:2014-06-07 08:22:37
【问题描述】:

在 Prestashop 中,我正在做一个模块。在该模块中,我有查看文件(智能模板)。在 smarty 中,我正在做表单,以便用户可以从前端提交表单。现在,当用户填写表单并单击提交时,表单应将所有 vales 保存到 thae 数据库。因此,为此,我在 smarty 中制作了这样的表格

<div id="content" class="form-wrapper" >
  <div class="form-content">
    <input type="text" id="name" name="name" placeholder="Name" /> <br />
    <input type="text" id="email" name="email" placeholder="email"/> <br />
    <input type="text" id="phone" name="phone" placeholder="Phone Number"/> <br />
    <input type="submit" name="submit-query" id="submit-enquiry" value="submit" />
  </div>
</div>

在提交值的文件中,我的代码是这样的

<?php
include '../../../config/settings.inc.php';
include '../../../config/defines.inc.php';
include '../../../config/config.inc.php';
include(dirname(__FILE__).'/../../../../init.php');


if(Tools::getValue('submit-query')) {
  $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
}
  else {
    $this->_html .= $this->displayError($this->l('You Have Some Errors'));
  }
?>

现在点击我的提交按钮时出现这样的错误

Fatal error: Using $this when not in object context in file.php on line 11

现在有人可以告诉我这里的问题是什么,我如何在 smarty 中为前端用户制作表单,以便他们可以提交表单并将值存储到数据库中。任何帮助和建议都将是非常可观的。谢谢

【问题讨论】:

  • 信息够清楚了。 $this 只能在类内部使用,在这个文件中,你在类外部使用它,这将不起作用。可能 _html 是某个类的属性,或者您需要以其他方式访问视图。我不知道 Prestashop,所以我帮不了你
  • @MarcinNabiałek 你有什么解决办法吗?
  • @navid 我不是这个问题的作者。你应该问 NewUser :)
  • @NewUser 你有什么解决办法吗?你是对的 MarcinNabialek :)
  • @navid 是的,我得到了解决方案。我刚刚使用 ajax 将 smarty 表单的值保存到数据库中。

标签: module smarty prestashop


【解决方案1】:

首先,我建议在模块内部进行处理,例如在init()函数中,您可以使用$this-&gt;context-&gt;link-&gt;getModuleLink('myModuleName');获取您的模块链接并将其添加到表单动作属性中,所有变量都可以使用$this-&gt;context-&gt;smarty-&gt;assign()分配。

在数据库中存储值是一个相当广泛的问题。你必须提供一些关于它的更多细节。

查看 Prestashop 的一些教程,例如Creating a Prestashop Module。您将在那里找到大部分答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-21
    • 2016-03-23
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 2014-08-20
    相关资源
    最近更新 更多