FAS Posted January 31, 2019 Share Posted January 31, 2019 I am adding an additonal field to the customer personal information making use of multi select checkboxes for the user to make his selection. I have it working in the front end, after a bit if a struggle!, but can't get the back office customer form to fully work. I can collect the the users selection and add it to the database, but I cannot figure out how to populate the customer form with exisiting values when updating, although it works fine with the type = select. The code in AdminCustomersController.php looks like this: public function renderForm() {........... $this->fields_value['angling_preference[]'] = explode(',',$obj->angling_preference); // Populates the field $this->fields_form = array(.......... // Checkbox doesn't populate with selection from the database array( 'type' => 'checkbox', 'name' => 'angling_preference[]', 'label' => $this->l('Type of Angling Preferred (Angling Type):'), 'class' => 'chosen', 'multiple' => true, 'required' => true, 'values' => array( 'query' => $list_angling_preferred, 'id' => 'id', 'name' => 'label' ) ), // Select works fine with selection from the database array( 'type' => 'select', 'label' => $this->l('Type of Angling Preferred (Angling Type):'), 'name' => 'angling_preference[]', 'class' => 'chosen', 'multiple' => true, 'size' => '6', 'required' => true, 'options' => array( 'query' => $list_angling_preferred, 'id' => 'id', 'name' => 'label', 'selected' =>'selected' ) ), The input checkbox works and I can collect the information that is selected and save it to the database, but I can't figure out how to populate it with the previously entered values added from the database. The input select works fine and populates with data from the database and does everything I need, but it ain't what I want!!!!! One other small thing, with the input select option the Size = 6 option doesn't work, am I making a syntatical error or if this not supported in Prestashop 1.6? Many thanks for your help. Link to comment Share on other sites More sharing options...
elementChaosu Posted February 7, 2023 Share Posted February 7, 2023 In 1.6, for multiple checkboxes in adminController, let's say I have this in renderForm() $this->fields_form['input'][] = [ 'type' => 'checkbox', 'name' => 'buttons[]', 'label' => $this->l('Checkboxes'), 'class' => 'chosen', 'multiple' => true, 'required' => true, 'values' => array( 'query' => $buttons, 'id' => 'id_button', 'name' => 'name' ), ]; According to this line in adminer/themes/default/template/helpers/form/form.tpl <input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" ... {if isset($fields_value[$id_checkbox]) && $fields_value[$id_checkbox]} checked="checked"{/if} /> I'd have to send stored values from db in $checkboxes into Helper->fields_value, in my case like this: foreach ($checkboxes as $cb) { $this->fields_value['buttons[]_'.$cb] = true; } voilá, checkboxes are checked 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