Prestashop在模块中设置了多个选择,并将其输入到输入中 [英] Prestashop set multiple select from the module and get them in the input
问题描述
我正在Prestashop中做一个小模块.在该模块中,我将multiselect与helperform一起使用.所以我的代码就是这样
I am doing a small module in Prestashop. In that module I have used multiselect with helperform. So my code is like this
array(
'type' => 'select',
'cols' => 8,
'class' => 'chosen-product-selct selected_products ',
'multiple' => true,
'label' => $this->l('Selected Products'),
'name' => 'selected_products[]',
'options' => array(
'query' => $product_query,
'id' => 'id',
'name' => 'product_name'
),
'desc' => $this->l('Select products from products list.'),
),
在这里,我将这些选择的值保存到数据库中.但是,当我进行编辑时,在框中没有选择任何已保存的值.盒子是完全空的.
Here I am saving those multiselected values to the database. But when I am doing edit no saved values has been selected in the box. The box is totally empty.
为了获得结果,我正在这样做
for getting the result I am doing this
public function getConfigFieldsValues() {
'selected_products[]' => Tools::getValue('selected_products', Configuration::get('selected_products')),
}
它不显示已输入的值.有人可以告诉我如何解决此问题吗?任何帮助和建议将是非常可观的.谢谢
Its not showing the values that has been entered.So can someone tell me how to solve this issue? Any help and suggestions will be really appreciable. Thanks
推荐答案
我找到了Prestashop多重选择表单帮助程序问题的解决方案.
I found a solution to the problem with Prestashop multiple select form helper issue.
为了使选择框正常工作,需要满足以下要求:
In order for the select box to work properly there are the following requirements:
- 输入名称应为"[]".例如:maker_ids []
- $ fields_value数组应具有相同名称的该元素:Manufacturer_ids []而不是Manufacturer_ids.
-
$ fields_value数组的相应项目的值应具有选定的值作为数组.例如:
- Input name should have '[]'. For example: manufacturer_ids[]
- $fields_value array should have this element with the same name: manufacturer_ids[] not manufacturer_ids.
The value of the $fields_value array's corresponding item should have selected values as array. For example:
$ fields_value ['manufacturer_ids []'] = array("120","145");
$fields_value['manufacturer_ids[]'] = array("120", "145");
我将提交的值另存为可序列化的字符串在数据库中,因此我以这种方式处理它:
I save the submitted values as sarialized string in Database, so I am handling it this way:
$selectedManufacturers = @unserialize($manufacturerIdsTakenFromDb);
if ($selectedManufacturers === false && $selectedManufacturers !== 'b:0;') {
$selectedManufacturers = array();
}
$fields_value['manufacturer_ids[]'] = $selectedManufacturers;
我在表单定义中的代码如下:
And my code in form definition looks like this:
array(
'type' => 'select',
'label' => $this->l('Manufacturers'),
'name' => 'manufacturer_ids[]',
'multiple' => true,
'options' => array(
'query' => array(
array('key' => '1', 'name' => 'Apple'),
array('key' => '2', 'name' => 'Samsung'),
array('key' => '3', 'name' => 'HTC'),
),
'id' => 'key',
'name' => 'name'
)
),
如果您的代码确实满足所有这些要求,但仍然无法正常工作,请告诉我,我们将很乐意协助您进行修复.
If your code does satisfy all these and it still does not work, please let me know, I will be happy to assist you to fix it.
这篇关于Prestashop在模块中设置了多个选择,并将其输入到输入中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!