【问题标题】:How to get value in checkbox Prestashop?如何在复选框 Prestashop 中获得价值?
【发布时间】:2016-09-01 14:12:32
【问题描述】:

我有一个函数 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 print_r($_POST) 它显示 checkBox_1 => on, checkBox_2 => on

这个类扩展了ModuleAdminController

【问题讨论】:

  • 哪个使用prestashop的版本?
  • 嗨,马特奥。我使用 1.6

标签: php checkbox prestashop prestashop-1.6 getvalue


【解决方案1】:

它在 fields_form 中缺少一个 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');

【讨论】:

    猜你喜欢
    • 2018-07-24
    • 1970-01-01
    • 2020-11-03
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    相关资源
    最近更新 更多