[英]prestashop show helper form checkbox checked
在Prestashop模塊中,我想顯示一個復選框。 為此我只是采取了這樣的輔助類方法
$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 header'),
'val' => '1',
'checked' => 'checked'
),
),
'id' => 'id',
'name' => 'name'
)
),
),
'submit' => array(
'title' => $this->l( 'Save Display Settings' ),
'class' => 'button pull-right',
'name' => 'save-main-display-settings',
)
),
);
但是這個只顯示了checkbow(未選中)。 我試圖將val變成0,1。 但它對我沒有用。 那么有人可以告訴我如何在幫助程序類中選中復選框。 任何幫助或建議都將非常適合。 謝謝
請刪除'checked'=>'checked'沒有必要。 其余的代碼是可以的 - 但它只是FORM結構定義,如果你想用數據填充它(選中復選框是數據定義而不是結構) 你需要向HelperForm提供數據 。
要選中復選框,請將其設置為:
$helper = new HelperForm();
$helper->fields_value['display_show_header'] = true;
名稱“display_show_header”是您的名稱“display”和“show_header”的串聯,您還可以在查看渲染復選框時在firebug中看到此名稱。
一個完整的例子:
/**
* Create the form that will be displayed in the configuration of your module.
*/
protected function renderForm()
{
$helper = new HelperForm();
// ...
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(),
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($this->getConfigForm()));
}
/**
* Helper Function to fill Checkbox Fields with Data
*/
public function getConfigFieldsValues()
{
$fields_value = array();
$shop_groups = $this->getShopGroups();
foreach($shop_groups as $shop_group) {
$shop_group_id = $shop_group['id_shop_group'];
$subshops = $this->getSubshops($shop_group['id_shop_group']);
foreach($subshops as $subshop) {
$shop_id = $subshop['id_shop'];
$fields_value['mwdsubshoporderstate_' . $shop_group_id . '_' . $shop_id] = $this->getStatus($shop_id);
}
}
return $fields_value;
}
/**
* Create the structure of form.
*/
protected function getConfigForm()
{
$form = array();
$form_input = array();
$shop_groups = $this->getShopGroups();
foreach($shop_groups as $shop_group) {
$subshops = $this->getSubshops($shop_group['id_shop_group']);
$form_input[] = array(
'type' => 'checkbox',
'label' => $this->l($shop_group['name'] . ' :'),
'desc' => $this->l(''),
'name' => 'mwdsubshoporderstate_' . $shop_group['id_shop_group'],
'values' => array(
'query' => $subshops,
'id' => 'id_shop',
'name' => 'name',
)
);
}
$form = array(
'form' => array(
'legend' => array(
'title' => $this->l('Diverse Einstellungen'),
'icon' => 'icon-cogs',
),
'input' => $form_input,
'submit' => array(
'title' => $this->l('Speichern'),
),
),
);
return $form;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.