Php Prestashop 1.6.1如何将tpl文件中表单的输入数据发布到mysql数据库? 来自希腊的问候,我正试图将一些来自tpl文件中表单的输入数据发布到数据库中的表中

Php Prestashop 1.6.1如何将tpl文件中表单的输入数据发布到mysql数据库? 来自希腊的问候,我正试图将一些来自tpl文件中表单的输入数据发布到数据库中的表中,php,mysql,forms,post,prestashop,Php,Mysql,Forms,Post,Prestashop,我尝试了很多方法,但都没有成功。(我对prestashop模块开发非常陌生) 提前感谢您的帮助 我创建表单的文件是: projectmodule.tpl <h4>{l s='Project Module' mod='projectmodule'}</h4> <div class="separation"></div> <form name="text_fields" method="post&

我尝试了很多方法,但都没有成功。(我对prestashop模块开发非常陌生)

提前感谢您的帮助

我创建表单的文件是: projectmodule.tpl

<h4>{l s='Project Module' mod='projectmodule'}</h4>
<div class="separation"></div>
<form name="text_fields" method="post" action="">
    <table>
        
        <tr>
            <td class="col-left">
                <label>{l s='First Field:'}</label>
            </td>
            <td>
                {include file="controllers/products/input_text_lang.tpl"
                    languages=$languages
                    input_name='firstfield'
                    input_value=$firstfield}
                <p class="preference_description"></p>
            </td>
        </tr>

        <tr>
            <td class="col-left">
                <label>{l s='Second Field:'}</label>
            </td>
            <td>
                {include file="controllers/products/input_text_lang.tpl"
                    languages=$languages
                    input_name='secondfield'
                    input_value=$secondfield}
                <p class="preference_description"></p>
            </td>
        </tr>

        <tr>
            <td class="col-left">
                <label>{l s='Third Field:'}</label>
            </td>
            <td>
                {include file="controllers/products/input_text_lang.tpl"
                    languages=$languages
                    input_name='thirdfield'
                    input_value=$thirdfield}
                <p class="preference_description"></p>
            </td>
        </tr>

        <tr>
            <td><input type ="submit" name = "submit_form" value = "Submit" /></td>
        </tr>
    </table>
</form>
我在数据库中创建表的文件是:install.php

$sql = array();

$sql[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'projectmodule` (
    `id_projectmodule` int(11) NOT NULL AUTO_INCREMENT,
    PRIMARY KEY  (`id_projectmodule`),
    `firstfield` varchar(255) NOT NULL,
    `secondfield` varchar(255) NOT NULL,
    `thirdfield` varchar(255) NOT NULL    
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8;';

foreach ($sql as $query) {
    if (Db::getInstance()->execute($query) == false) {
        return false;
    }
}
标准方式:

您必须在模块中添加“actionProductUpdate”挂钩

此外,还必须具有自定义的objectModel

public function hookActionProductUpdate($params)
{
    require_once (_PS_MODULE_DIR_ . $this->name .'/models/ProjectModuleCore.php');
    $id_product = (int)Tools::getValue('id_product');
    if($id_product && Tools::getValue('submit_form')) {
        $id = null;
        // Some code to get if exist $id
        $fn = new ProjectModuleCore($id);
        $fn->id_product = $id_product;
        $fn->firstfield = Tools::getValue('firstfield');
        $fn->secondfield = Tools::getValue('secondfield');
        $fn->thirdfield = Tools::getValue('thirdfield');
        $fn->save();
    }
}
在文件“ProjectModuleCore.php”中:


“没有任何成功”的使用不是很充分。你做了什么?您是否已检查浏览器控制台是否存在错误?您检查过web服务器错误日志了吗?您是否查看了浏览器向服务器发送的内容?服务器是否接收到您期望的内容?需要更多的细节。您需要缩小问题的范围。我已经尝试使用{php}if(Tools::isSubmit('submit_form')){Db::getInstance()->Execute(“INSERT INTO ps_projectmodule('firstfield','secondfield','thirdfield')值(Tools::getValue('firstfield','secondfield','thirdfield'))));}{/php}在tls文件中插入以下代码,但没有起作用,我还尝试了在我的表单中使用相同代码指向php文件的操作,例如Db::getInstance()->Execute(“插入ps_projectmodule('firstfield','secondfield','thirdfield')值(tools::getValue('firstfield','secondfield','thirdfield'));)而且它也不起作用。当然,浏览器控制台目前有错误,但即使没有任何错误,它也无法工作。即使我看到一些错误日志,我也无法理解我看到的内容。服务器正确创建了表,但我不知道如何遵循输入数据的路线。首先,我要感谢您的时间和努力。但是仍然没有,没有从表单数据中得到数据库结果。我在代码中的某个点进行了更正,该点在hookActionProductUpdate函数中使用了符号“|”而不是“}”,但仍然没有任何结果。你能给我一些其他的建议吗?谢谢,我有许多与您的模块类似的模块(带有nop)。请确保该模块位于action product update挂钩中。请原谅我的持久性,但您提到我应该确保该模块位于hookActionProductUpdate中。你这是什么意思?谢谢只需将这个新的钩子添加到“安装”方法中,并从adminI重置您的模块。我已经在安装函数中声明了钩子,我还尝试卸载该模块,我删除了数据库中的表,并重新安装了该模块,从一开始就在数据库中创建了该模块和表。所有这些都不起作用。
public function hookActionProductUpdate($params)
{
    require_once (_PS_MODULE_DIR_ . $this->name .'/models/ProjectModuleCore.php');
    $id_product = (int)Tools::getValue('id_product');
    if($id_product && Tools::getValue('submit_form')) {
        $id = null;
        // Some code to get if exist $id
        $fn = new ProjectModuleCore($id);
        $fn->id_product = $id_product;
        $fn->firstfield = Tools::getValue('firstfield');
        $fn->secondfield = Tools::getValue('secondfield');
        $fn->thirdfield = Tools::getValue('thirdfield');
        $fn->save();
    }
}
<?php
class iProductFnbCore extends ObjectModel
{
    public $id_product;
    public $firstfield;
    public $secondfield;
    public $thirdfield;

    public static $definition = array(
        'table' => 'projectmodule',
        'primary' => 'id_projectmodule',
        'fields' => array(
            'id_product' =>      array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
            'firstfield' =>              array('type' => self::TYPE_STRING, 'validate' => 'isString'),
            'secondfield' =>         array('type' => self::TYPE_STRING, 'validate' => 'isString'),
            'thirdfield' =>          array('type' => self::TYPE_STRING, 'validate' => 'isString'),
        )
    );
}