如何在复选框Prestashop中获取价值?

时间:2016-09-01 14:12:33

标签: php checkbox prestashop prestashop-1.6 getvalue

我有一个函数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'
        )
    );

我需要获取复选框的值以插入数据库

print_r($_POST)它显示checkBox_1 => on,checkBox_2 =>上

此课程扩展ModuleAdminController

1 个答案:

答案 0 :(得分:1)

它在 fields_form 中缺少表单数组。 Prestashop renderForm 的正确结构必须是:

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

print_r($_POST)会输出如下内容:

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

获取复选框值:

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