[英]codeigniter form to submit selected dropdown value
I need to make a form that have a dropdown to select record and when click on the submit button can edit. 我需要制作一个具有下拉菜单的表单以选择记录,然后单击“提交”按钮即可进行编辑。 Everything is working fine just the button not get the selected id.
一切工作正常,只是按钮未获取所选的ID。
Here is a screenshot of my form: 这是我的表单的屏幕截图:
<form action="<?php echo base_url();?>admin/edit_instrumento; ?>" method="post" id="instrumentos_form">
<div class="col-lg-12 well">
<div class="form-group">
<div class="form-inline">
<div class="form-group">
<div class="formSep">
<p><span class="label label-default">Selecione Usuário</span></p>
<div class="">
<div class="col-sm-12 col-md-12">
<select class="uni_style" name="nome" id="user_drop">
<option value="">Selecione</option>
<?php foreach($users as $member){ ?>
<option value="<?php echo $member->user_id; ?>"><?php echo $member->nome; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="formSep">
<p><span class="label label-default">Selecione o Tag</span></p>
<div class="">
<div class="col-sm-12 col-md-12">
<select class="uni_style" name="tag" id="tag_drop" >
<option value="">Selecione</option>
<?php
$sl_class=$row['instrumento_id'];
?>
<?php foreach($instrumentos as $instrumento){ ?>
<option value="<?php echo $instrumento['instrumento_id']; ?>"><?php echo "Tag: { ". $instrumento['tag']." } →Instrumento: { ". $instrumento['instrumento_nome']." }"; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
</div>
<hr class="hrmag"/>
<div class="pull-right">
<p><input class="btn btn-primary" type="submit" name="submit" value="Editar" /></p>
</div><br/>
</div>
</div>
</form>
public function instrumento($instrumento_id){
$posts = $this->input->post();
$lista = $this->instrumento_model->get_instrumento($instrumento_id);
$html="";
foreach ($lista as $k => $v) {
$html.= '<option value="'.$v['instrumento_id'].'">'.$v['instrumento_nome'].'</option>';
}
echo $html;
}
function edit_instrumento($instrumento_id){
$data['success']=0;
if($_POST){
$data_post = array(
'user_id' => $_POST['nome'],
'instrumento_nome' => $_POST['instrumento_nome']
);
$this->instrumento_model->update_instrumento($instrumento_id,$data_post);
$data['success']=1;
$this->load->view('admin/edit_instrumento',$data);
redirect(base_url().'admin/h');
}
$data['instrumento']=$this->instrumento_model->get_instrumento($instrumento_id);
$this->load->view('admin/edit_instrumento',$data);
}
function get_instrumentos(){
$this->db->select('*');
$this->db->from('instrumentos');
$this->db->join("users", "users.user_id = instrumentos.user_id",'inner');
$query = $this->db->get();
return $query->result_array();
}
function get_instrumento($instrumento_id){
$this->db->select()->from('instrumentos')->where(array('instrumento_id'=>$instrumento_id));
$query=$this->db->get();
return $query->first_row('array');
}
function update_instrumento($instrumento_id,$data){
$this->db->where('instrumento_id',$instrumento_id);
$this->db->update('instrumentos',$data);
}
You are taking wrong post value 您的帖子价值有误
In view its tag
, 查看其
tag
,
<select class="uni_style" name="tag" id="tag_drop" >
in controller its instrumento_nome
在控制器中它的
instrumento_nome
'instrumento_nome' => $_POST['instrumento_nome']
This is wrong, use same name in both the places. 这是错误的,请在两个地方使用相同的名称。
Solution 解
Either change name in view, 在视图中更改名称,
name="instrumento_nome" and in controller use as $_POST['instrumento_nome']
or
name="tag" and in controller use as $_POST['tag']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.