Checkbox prestashop中的复选框值

Checkbox prestashop中的复选框值,checkbox,prestashop-1.6,Checkbox,Prestashop 1.6,我正在使用prestashop,并尝试使用HelpPerform从带有复选框的表单中获取值 所以我所拥有的是: $fields_form[0]['form']= [ 'legend'=> [ 'title'=> $this->l('Indexation') ] , 'input'=>[ [ 'type'=>'text',

我正在使用prestashop,并尝试使用HelpPerform从带有复选框的表单中获取值

所以我所拥有的是:

$fields_form[0]['form']= [
        'legend'=> [
            'title'=> $this->l('Indexation')
        ] ,
        'input'=>[
            [
                'type'=>'text',
                'label'=> $this->l('Base(s) à indexer'),
                'name'=>'options',
                'size'=>20,
                'required'=>true
            ]
        ],
        'submit'=>[
            'title' => $this->l('Save'),
            'class' => 'btn btn-default pull-right'
        ]
    ];
然后

$helper = new HelperForm();
[...]
$helper->toolbar_btn = array(
        'save' =>
            array(
                'desc' => $this->l('Save'),
                'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
                    '&token='.Tools::getAdminTokenLite('AdminModules'),
            ),
        'back' => array(
            'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
            'desc' => $this->l('Back to list')
        )
    );

    // Load current value
    $helper->fields_value['options'] = Configuration::get('options');

    return $helper->generateForm($fields_form);
在我的
getContent
中,我有:

$my_module_name = strval(Tools::getValue('options'));
return $my_module_name;
所以在那之前我没有问题。我在文本输入中写入“test”,然后返回“test”,但我不想要文本输入我想要复选框输入,因此我更改了以下表单:

 $fields_form[0]['form']= [
        'legend'=> [
            'title'=> $this->l('Indexation')
        ] ,
        'input'=>[
            [
                'type'=>'checkbox',
                'label'=> $this->l('Base(s) à indexer'),
                'name'=>'options',
                'required'=>true,
                'values'=>[
                    'query'=>$options,
                    'id'=>'id',
                    'name'=>'name'
                ]
            ]
        ],
        'submit'=>[
            'title' => $this->l('Save'),
            'class' => 'btn btn-default pull-right'
        ]
    ];
美元期权是:

$options = [
        [
            'id'=>1,
            'name'=>'test'
        ],
        [
            'id'=>2,
            'name'=>'test2'
        ]
    ];
在我的
getContent()
返回(Tools::getValue('options')
但有了它,就什么也看不见了


另外,如果我返回sizeof(Tools::getValue('options))
它会给我1,不管我用复选框勾选什么

$fields_form[0]['form']= [
    'legend'=> [
        'title'=> $this->l('Indexation')
    ] ,
    'input'=>[
        [
            'type'=>'checkbox',
            'label'=> $this->l('Base(s) à indexer'),
            'name'=>'options[]',
            'required'=>true,
            'values'=>[
                'query'=>$options,
                'id'=>'id',
                'name'=>'name'
            ]
        ]
    ],
    'submit'=>[
        'title' => $this->l('Save'),
        'class' => 'btn btn-default pull-right'
    ]
];
然后,选项应该有一个值:

$options = [
    [
        'id'=>1,
        'name'=>'test',
        'val' => 1
    ],
    [
        'id'=>2,
        'name'=>'test2',
        'val' => 2
    ]
];
然后,您可以通过以下方式获得检查值:

Tools::getValue('options')
编辑: 在1.6中,我们为助手提供了管理tpl:

{foreach $input.values.query as $value}
    {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]}
    <div class="checkbox{if isset($input.expand) && strtolower($input.expand.default) == 'show'} hidden{/if}">
        {strip}
            <label for="{$id_checkbox}">
                <input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" class="{if isset($input.class)}{$input.class}{/if}"{if isset($value.val)} value="{$value.val|escape:'html':'UTF-8'}"{/if}{if isset($fields_value[$id_checkbox]) && $fields_value[$id_checkbox]} checked="checked"{/if} />
                {$value[$input.values.name]}
            </label>
        {/strip}
    </div>
{/foreach}
此外,要在加载页面时进行检查,我们将传递值以满足条件:

{if isset($fields_value[$id_checkbox]) && $fields_value[$id_checkbox]} checked="checked"{/if}

你救了我。如果我能再问你一件事。但我还是有个问题。假设我有5个选择。如果我选中五个选项中的两个,它只会给我一个带有['on','on']的数组。不管我检查第一,第二,第三。。。选项我无法知道选中了哪个选项。这就是为什么您可能需要为每个选项设置不同的值或(val)。您应该会收到一个包含所选值的数组。在上面的示例中,如果同时选中这两个选项,则会收到[1,2],它不起作用,但这是因为它是val而不是value。感谢您的帮助,您已经编辑了信息,并添加了如何在打开页面时检查值。
{if isset($fields_value[$id_checkbox]) && $fields_value[$id_checkbox]} checked="checked"{/if}