Jump to content

Show helper form checkbox checked


Recommended Posts

Hi,

 

In a module I want to show a checkbox checked by default. For that I just took the helper class methods like this

 



$display_settings = array(
'form' => array(
'legend' => array(
'title' => $this->l( 'Display Settings' ),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'checkbox',
'name' => 'display',
'values' => array(
'query' => array(
array(
'id' => 'show_header',
'name' => $this->l('show'),
'val' => '1',
'checked' => 'checked'
),
),
'id' => 'id',
'name' => 'name'
)
),
),
'submit' => array(
'title' => $this->l( 'Save Settings' ),
'class' => 'button pull-right',
'name' => 'save-settings',
)
),
);


 

but this one is showing only checkbow (not checked). I tried to chnage val into 0,1. But it did not worked for me. So can someone tell me how to make a checkbox checked in helper class. Any help or suggestions will be really  appreceable. Thanks

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 1 year later...

@prestashop_newuser, to solve your (old) post :

  • Remove your `'checked' => 'checked'`
  • Add this code below yours :
$helper = new HelperForm();
$helper->fields_value['save-settings_show_header'] = 'true';
return $helper->generateForm(array($display_settings));

The "save-settings_show_header" is a auto-Prestashop's concatenation of your form's group name "save-settings" and option's id "show_header".

 

In place of "true", you can use "1" to set checkbox as checked (or "false" or "0" to keep it unchecked).

 

Solution found here : http://stackoverflow.com/questions/25379126/prestashop-show-helper-form-checkbox-checked

Link to comment
Share on other sites

I solved it
this is my example on helper form

$picking_history = array(array('id'=>'history_1', 'name' => '', 'val' => '1'));

 
                    array(
                        'type' => 'checkbox',
                        'label' => $this->l('Display history block on order page'),
                        'name' => 'SHOW_HISTORY',
                        'values' => array(
                            'query' =>$picking_history,
                            'id' => 'id',
                            'name' => 'name',
                            'value' => '1'
                        ),
                        'tab' => 'config',
                    ),
in getConfigFormValues function
I return  array(
            'PICKINGCART_HISTORY_history_1' => Configuration::get('PICKINGCART_HISTORY'),
);
and It working now
  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...