Prestashop 1.6.1 Helper表单字段未定义索引

问题描述 投票:0回答:2

我正在努力解决这个问题几个小时:我正在尝试在Prestashop中使用HelperForm类生成的表单中为自定义模块添加新字段。

我尝试在getContent()函数中为模块的配置页面执行此操作

接受以下字段并且它有效:

array(
    'type' => 'file',
    'label' => $this->l('Button image'),
    'id' => 'button_image_path',
    'name' => 'button_image_path',
    'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)

但是,当我尝试添加其他字段时:

array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.'
)

它给出了这个错误:

Notice on line 387 in file D:\wamp\www\qmart.ro\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code
[8] Undefined index: CROSSSELLING_NBR

但是,仍然会生成输入,它看起来像这样:

<input type="text" name="CROSSSELLING_NBR" id="CROSSSELLING_NBR" value="" class="">

我尝试了什么:

  • 例如,将输入类型从文本更改为颜色,并且它给出了相同的错误
  • 更改标签内容和名称内容,仍然出现错误

我没有更改核心文件中的任何内容。

因此,正在为这些输入构建表单,但这种“未定义的索引”仍然会发生。

prestashop smarty form-helpers undefined-index formhelper
2个回答
0
投票

因此,很明显它们会强制您为输入选择一些默认值。

我简单地通过添加这一行来解决它:

$helper->fields_value['CROSSSELLING_NBR'] = '';

0
投票

根据你的代码......

array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.'
)

你在'desc'中有一个错误,你需要关闭最后的括号,这应该有效......

array(
    'type' => 'text',
    'label' => $this->l('Number of displayed products'),
    'name' => 'CROSSSELLING_NBR',
    'desc' => $this->l('Set the number of products displayed in this block.')
)
© www.soinside.com 2019 - 2024. All rights reserved.