Search code examples
phpxamppprestashopprestashop-1.7

Adding a dropdown menu in Prestashop 1.7 module


I'm so beginner in Prestashop 1.7, I wanted to add a dropdown select section in my banner module to select the way to open the banner link.

but the selected value is never passed to the HTML, the code below IS passed but the one under isn't, can you please assist me? [enter image description here][1]

array(
                        'type' => 'text',
                        'lang' => true,
                        'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
                        'name' => 'BANNER_DESC',
                        'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
                    )
array(
                        'type' => 'select', //select
                        'lang' => true,
                        'label' => $this->trans('Banner tab', array(), 'Modules.Banner.Admin'),
                        'name' => 'BANNER_TAB',
                        'required'=>'true',
                        'options' => array(
                            'query' => array(
                                array('key' => '_blank', 'name' => 'New tab'),
                                array('key' => '_self', 'name' => 'Same tab'),
                            ),
                            'id' => 'key',
                            'name' => 'name'
                        ),
                        
                        'desc' => $this->trans('Please select the way to open the link.', array(), 'Modules.Banner.Admin')
                    )

This is how it looks in the Backoffice: Here


Solution

  • You not only need to add a new field to your form but also handle saving the data from it.

    Take a look at a few examples: https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L122

    Notice how the module author managed to save each configuration field from the form. This is what you need to do.

    If you want to have access to data in your view, you have to pass it: https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L244

    Maybe after you added a new field, you forgot to handle the saving + passing to the view?