我想从数据库中获取复选框值并在表单中显示,当点击提交时,新值应该在Prestashop中更新。
我使用获取的数据库值完成了foreach
,但只显示了一个值。
我的代码是:
protected function getConfigForm()
{
$sql = 'SELECT id_order_state,name FROM '._DB_PREFIX_.'order_state_lang';
$results = Db::getInstance()->ExecuteS($sql);
foreach ($results as $row) {
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'checkbox',
'label' => $this->l('Select Required Status'),
'required' => true,
'values' => array(
'query' => array(
array(
'id' => 'AllFields',
'name' => $this->l('All Fields'),
'val' => 'All',
),
array(
'id' => 'OrderID',
'name' => $this->l($row['name']),
'val' => $row['id_order_state'],
'required' => true,
),
),
'id' => 'id',
'name' => 'name'
),
),
),
// array(
// 'type' => 'text',
// 'name' => 'EXPORTORDERS_LOCATION',
// 'label' => $this->l('Export Location'),
// ),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}
}
答案 0 :(得分:1)
您将从foreach
循环内的方法返回。然后,您将返回单个值。您应首先在foreach
循环内构建一个values数组,然后构建表单:
protected function getConfigForm()
{
$sql = 'SELECT id_order_state,name FROM '._DB_PREFIX_.'order_state_lang';
$results = Db::getInstance()->ExecuteS($sql);
$values_query = array(array(
'id' => 'AllFields',
'name' => $this->l('All Fields'),
'val' => 'All',
));
foreach ($results as $row) {
$values_query[] = array(
'id' => 'OrderID',
'name' => $this->l($row['name']),
'val' => $row['id_order_state'],
'required' => true,
);
}
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'checkbox',
'label' => $this->l('Select Required Status'),
'required' => true,
'values' => array(
'query' => $values_query,
'id' => 'id',
'name' => 'name'
),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}