vdhoangson
vdhoangson

Reputation: 39

How to get value in checkbox Prestashop?

i have a function renderForm

$this->fields_form = array(
        'tinymce' => true,
        'legend' => array(
            'title' => $this->l('Category'),
            'icon' => 'icon-folder'
        ),
        'input' => array(

            array(
                'type' => 'checkbox',
                'label' => $this->l('Group access'),
                'name' => 'checkBox',
                'values' => array(
                    'query' => Group::getGroups($this->id_lang),
                    'id' => 'id_group',
                    'name' => 'name'
                ),
                'unidentified' => $unidentified_group_information,
                'guest' => $guest_group_information,
                'customer' => $default_group_information,
                'info_introduction' => $this->l('You now have three default customer groups.'),
                'hint' => $this->l('Mark all of the customer groups which you would like to have access to this category.')
            )
        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'btn btn-large btn-success pull-right'
        )
    );

i need get value of checkbox for insert into database

i print_r($_POST) it show checkBox_1 => on, checkBox_2 => on

this class extends ModuleAdminController

Upvotes: 0

Views: 1143

Answers (1)

Klemart3D
Klemart3D

Reputation: 338

It missing a form array inside the fields_form. Correct structure for Prestashop renderForm must be:

$fields_form = array(
    'form' => array(
        'tinymce' => true,
        'legend' => array( ... ),
        'input' => array( ... ),
        'submit' => array( ... )
    )
)

A print_r($_POST) will output something like:

Array (
    [Form_id] => 1
    [form_id] => Form_id
    [checkBox] => 1
    [tab] => AdminModules
)

To get the checkbox value(s):

$checkBoxValues = Tools::getValue('checkBox');

Upvotes: 1

Related Questions