【发布时间】: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