amarsdml Posted December 16, 2013 Share Posted December 16, 2013 I am saving the values in the form 10,20,30,40 into the database. In edit page i having HelperForm as below. array('type' => 'select' , // This is a <select> tag.'label' => $this->l('Companion Model Nos:') , // The <label> for this <select> tag.'desc' => $this->l('Choose Companion Model Numbers') , // A help text, displayed right next to the <select> tag.'name' => 'companion_model_nos[]' , // The content of the 'id' attribute of the <select> tag.'required' => true , // If set to true, this option must be set.'multiple' => true ,'class' => 'chosen' ,'options' => array('query' => $modelNoOptions , // $options contains the data itself.'id' => 'id_option' , // The value of the 'id' key must be the same as the key for 'value' attribute of the <option> tag in each $options sub-array.'name' => 'name' , // The value of the 'name' key must be the same as the key for the text content of the <option> tag in each $options sub-array.))I am not getting already saved values selected in select tag. Please help me! Link to comment Share on other sites More sharing options...
ajinkya Posted August 1, 2014 Share Posted August 1, 2014 (edited) I am saving the values in the form 10,20,30,40 into the database. In edit page i having HelperForm as below. array( 'type' => 'select' , // This is a <select> tag. 'label' => $this->l('Companion Model Nos:') , // The <label> for this <select> tag. 'desc' => $this->l('Choose Companion Model Numbers') , // A help text, displayed right next to the <select> tag. 'name' => 'companion_model_nos[]' , // The content of the 'id' attribute of the <select> tag. 'required' => true , // If set to true, this option must be set. 'multiple' => true , 'class' => 'chosen' , 'options' => array( 'query' => $modelNoOptions , // $options contains the data itself. 'id' => 'id_option' , // The value of the 'id' key must be the same as the key for 'value' attribute of the <option> tag in each $options sub-array. 'name' => 'name' , // The value of the 'name' key must be the same as the key for the text content of the <option> tag in each $options sub-array. ) ) I am not getting already saved values selected in select tag. Please help me! I am sure that you did implode somewhere to store comma-separated values. Can you tell me if you are doing explode anywhere? If you are not doing implode while storing then I would like to know how you are able to store comma-separated values in the database. Edited August 1, 2014 by ajinkya (see edit history) Link to comment Share on other sites More sharing options...
arturocu81 Posted August 20, 2014 Share Posted August 20, 2014 (edited) Hi, I have the same problem. I explode the values and set them into the variable $this->fields_value['especialidad[]'] = explode(',',$obj->especialidad); but take only the firts value. If I change the configuration, without use the class 'chosen', work perfectly, but use the chosen class is important because of the kind of client who will manipulate the system. Why happen this? Can anybody help me? Thanks in advance! Edited August 20, 2014 by arturocu81 (see edit history) 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. 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. Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 20, 2017 Share Posted September 20, 2017 in all the cases of select question this stupid answerd are posted.. please a example! where we cacht the serialized send! this answerd only provided the unserialized receive, but where to send serialized? Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 20, 2017 Share Posted September 20, 2017 I am saving the values in the form 10,20,30,40 into the database. ho do you get 10,20,30 into the table field? 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