Php Codeigniter表单中的表单_dropdown()返回错误值
我正在更新来自Tank_auth的一些控件,并试图在register_表单中插入一个下拉列表。下拉列表包含来自sql查询的数组。 型号代码:Php Codeigniter表单中的表单_dropdown()返回错误值,php,Php,我正在更新来自Tank_auth的一些控件,并试图在register_表单中插入一个下拉列表。下拉列表包含来自sql查询的数组。 型号代码: public function get_group(){ $query = $this->DB1->query('SELECT val7 from table group by val7;'); if($query->num_rows()>0){ $group= array(); foreach($quer
public function get_group(){
$query = $this->DB1->query('SELECT val7 from table group by val7;');
if($query->num_rows()>0){
$group= array();
foreach($query->result_array() as $r){
$group[$r['val7']] = $r['val7'];
}
}
return $group;
}
以及查看代码:
<div class="control-group">
<?php echo form_label('Grupo', $grupo['id'], array('class' => 'control-label')); ?>
<div class="controls">
<?php echo form_error('grupo'); ?>
<?php echo form_dropdown('grupo',$list_groups)?>
<p class="help-block"></p>
</div>
最好的办法是什么
非常感谢
编辑
有关php代码的更多信息:
查看文件:
<!--Top of file, more code-->
$grupo = array(
'name' => 'grupo',
'id' => 'grupo',
'value' => set_value('grupo'),
);
<!--rest of the form, start the form_dropdown()-->
<div class="control-group">
<?php echo form_label('Grupo', $grupo['id'], array('class' => 'control-label')); ?>
<div class="controls">
<?php echo form_error('grupo'); ?>
<?php echo form_dropdown('grupo',$list_groups)?>
<p class="help-block"></p>
</div>
<!--rest of the form, end of view-->
结果是servicegroup的一个空变量。
我认为这是表单_dropdwon没有将值传递给控制器的问题
谢谢你的帮助。解决了!!
参数顺序有一个简单的问题。在浏览器中生成表单时,是使用正确的值进行渲染,还是所有值都设置为0?如果使用正确的值进行渲染,则会显示一个包含3个值的下拉列表:cliente1、cliente2、cliente3。我尝试手动写入数组,但它仍然在DB字段中插入一个0。谢谢如果其全部正确呈现,则可以通过各种不同的方式输入0。2常见问题,如果对值进行强制转换(bool)或(int),或者该值未正确传递给db方法。您能否显示控制器和模型代码,因为这就是问题所在,并将帮助其他人为您调试它?编辑文章,提供有关代码的更多信息。谢谢麦克:)
<!--Top of file, more code-->
$grupo = array(
'name' => 'grupo',
'id' => 'grupo',
'value' => set_value('grupo'),
);
<!--rest of the form, start the form_dropdown()-->
<div class="control-group">
<?php echo form_label('Grupo', $grupo['id'], array('class' => 'control-label')); ?>
<div class="controls">
<?php echo form_error('grupo'); ?>
<?php echo form_dropdown('grupo',$list_groups)?>
<p class="help-block"></p>
</div>
<!--rest of the form, end of view-->
<!--top of the controller and resto of the code, start validation-->
$this->form_validation->set_rules('grupo', 'Grupo', 'trim|required|xss_clean');
<!--rest of all validations, pass the values to $data array and create_user function-->
$this->form_validation->set_value('grupo'),
<!--start function with arguments-->
function create_user($username, $email, $password, $email_activation, $grupo){
$data = array(
'username' => $username,
'password' => $hashed_password,
'email' => $email,
'servicegroup' => $grupo,
'last_ip' => $this->ci->input->ip_address(),
);
if ($this->db->insert($this->table_name, $data)) {
$user_id = $this->db->insert_id();
if ($activated) $this->create_profile($user_id);
return array('user_id' => $user_id);
}