Riya92 Posted October 9, 2015 Share Posted October 9, 2015 I have added a multiselect dropdown field in customer adding form in admin. I have created new field in database. But I am not getting how to store the value of this new field to database. Please help I have added this code to AdminCustomersController.php array( 'type' => 'select','multiple' => true,'label' => $this->l('Branch Location'),'name' => 'branch_location','required' => false,'options' => array('query' => $list_branch_arr,'id' => 'branch_location','name' => 'name'),'col' => '4','hint' => array($this->l('Please choose the branch name from the branch list.')) Link to comment Share on other sites More sharing options...
NemoPS Posted October 10, 2015 Share Posted October 10, 2015 See this:http://nemops.com/extending-prestashop-objects/#.VhjJjvnzrmgYou need to extend the object (customer, in this case) Link to comment Share on other sites More sharing options...
Riya92 Posted October 12, 2015 Author Share Posted October 12, 2015 Thanks for your help. But I have already added the new field. But From multiple select dropdown ..it is only taking one value saved to database. I want to save all selected value from multiselect dropdown to database. Please help. Link to comment Share on other sites More sharing options...
gabdara Posted October 12, 2015 Share Posted October 12, 2015 For a multiple select the name should end with [] ( eg. myselectname[] ). This will post an array of the selected values on submit. In addition to Nemo's tutorial you should also extend the add() function to implode the select array into a csv string that will be saved into database, also in the constructor explode back to array. 1 Link to comment Share on other sites More sharing options...
Riya92 Posted October 12, 2015 Author Share Posted October 12, 2015 When I am putting [] in end of field name it is showing error 'field is invalid'. Is there any way to solve this. Link to comment Share on other sites More sharing options...
gabdara Posted October 12, 2015 Share Posted October 12, 2015 The function that returns the the array with values for the fields ( the function getConfigFieldsValues() in most of default modules ) must have also [] at the end of that field key. Link to comment Share on other sites More sharing options...
Riya92 Posted October 20, 2015 Author Share Posted October 20, 2015 I have simply added this in controller and it worked for me if (Tools::isSubmit('submitAddcustomer')) { $dept = Tools::getValue('department_or_branch'); $departments = implode(',', $dept); $id = Tools::getValue('id_customer'); $sql = 'UPDATE zig_customer SET department_or_branch="'.$departments.'" WHERE id_customer='.$id; $interested = Db::getInstance()->executeS($sql); } Link to comment Share on other sites More sharing options...
mckaygerhard Posted September 21, 2017 Share Posted September 21, 2017 hi! i have the same problem i want to store the input multiselect field as "1,2,3" in the table.. i noted that i must implote that values after the postprocess, but read here that i must extend the "add" how i do that? @gabdara 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" 1 Link to comment Share on other sites More sharing options...
Recommended Posts