Jump to content

HelperForm multiple select


amarsdml

Recommended Posts

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

  • 7 months later...

 

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 by ajinkya (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

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 by arturocu81 (see edit history)
Link to comment
Share on other sites

  • 1 year later...

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

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...