Prestashop 1.6.1 Helper Form字段未定义索引

时间:2018-08-08 09:25:17

标签: prestashop smarty form-helpers undefined-index formhelper

我为此苦苦挣扎了好几个小时: 我正在尝试将新字段添加到使用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="">

我尝试过的事情:

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

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

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

2 个答案:

答案 0 :(得分:0)

因此,显然他们强迫您为输入选择一些默认值。

我通过添加以下行来解决它:

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

答案 1 :(得分: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.')
)
相关问题