gr4devel Posted September 17, 2014 Share Posted September 17, 2014 (edited) How I'm supposed to set the selected options for a multiple select input type inside an HelperForm? Here's the code that should handle the display of the over mentioned select input type: ... array( 'type' => 'select', 'name' => 'field_name[]', 'id' => 'field_name', 'label' => $this->l('Multiple value select field'), 'desc' => $this->l('...'), 'multiple' => true, 'options' => array( 'query' => $field_values, 'id' => 'id_field_value', 'name' => 'field_value_name' ) ), ... Just for the record, the trailing square brackets after the input type name are needed to properly populate the POST variable with all the multiple value selected. Here's the code that should handle the correct selection of the already saved (i.e. selected) options: ... $helper->tpl_vars = array( 'uri' => $this->getPathUri(), 'fields_value' => [ ... 'field_values[]' => $field_values, ... ], 'languages' => $this->context->controller->getLanguages(), 'id_language' => $current_back_office_language ); ... As always there is no clear documentation that clarifies how to structure the $field_values field. I've tried a bunch of different options like a plain array of indexes or an hash with each index identified by the actual name (i.e. string) but nothing seems to work. Every help will be appreciated. Thanks. Edited September 17, 2014 by gr4devel (see edit history) 1 Link to comment Share on other sites More sharing options...
fusillicode Posted September 17, 2014 Share Posted September 17, 2014 (edited) Same thing here I'm also interested in a possible solution. Edited September 17, 2014 by fusillicode (see edit history) Link to comment Share on other sites More sharing options...
fusillicode Posted September 19, 2014 Share Posted September 19, 2014 Bump. Sry community but this issue is getting rly a bit pressing. Link to comment Share on other sites More sharing options...
fusillicode Posted September 19, 2014 Share Posted September 19, 2014 I have searched online through the issues and haven't found nothing about this problem I created a new one: http://svel.to/eks Link to comment Share on other sites More sharing options...
fusillicode Posted September 19, 2014 Share Posted September 19, 2014 Ok it seems there is actually a problem that is currently being handled by the support! For all the updates about the issue you can follow the over mentioned link http://svel.to/eks Cheers! Link to comment Share on other sites More sharing options...
ELEGANTAL Posted November 2, 2015 Share Posted November 2, 2015 I have answered this question on stackoverflow and on this forum (p=2179775). Here I am providing the same answer which I think should solve the issue you have faced: 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: 1. Input name should have '[]'. For example: manufacturer_ids[] 2. $fields_value array should have this element with the same name: manufacturer_ids[] not manufacturer_ids. 3. 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"); 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. 1 Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 20, 2017 Share Posted September 20, 2017 this stupid answer does not said nothig.. a example code will be much appreciated! Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 22, 2017 Share Posted September 22, 2017 i found the solution, due in this "forum comunity" there's no "comunity" only "forum sales" THE COMPLETE CODE AND ALL THE STEPS ARE AT: https://groups.google.com/forum/m/?hl=es#!topic/venenuxsarisari/z8vfPsvFFjk here i put only the most important parts.. as mentioned int he previous link, added a new fiel in the model definition, class and the table sql this method permits to stored in the db as "1,2,3" so you can use only a single field to relation that multiple selected values, a better could be using groupbox but its quite difficult, take a look to the AdminCustomers controller class in the controllers directory of the prestachop, this has a multiselect group that used a realtional table event stored in single field then in the helper form list array of inputs define a select as: array( 'type' => 'select', 'label' => $this->l('Select and employee'), 'name' => 'id_employee_tech', 'required' => false, 'col' => '6', 'default_value' => (int)Tools::getValue('id_employee_tech'), 'options' => array( 'query' => Employee::getEmployees(true), // el true es que solo los que estan activos 'id' => 'id_employee', 'name' => 'firstname', 'default' => array( 'value' => '', 'label' => $this->l('ninguno') ) ) ), an then override the post process too public function postProcess() { if (Tools::isSubmit('submitTallerOrden')) { $_POST['id_employee'] = implode(',', Tools::getValue('id_employee')); } parent::postProcess(); } this make stored in the db as "1,2,3" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now