現在、データベースから取得したメニュー項目を含むドロップダウンメニューを含むフォームがあります。 私が達成しようとしているのは、ユーザーがこれらの値の1つを選択してデータベースに追加できるようにすることです。このフォームは現在、データベースを除いて正しく送信して挿入しています。ドロップダウンの値をデータベースに追加しようとすると、すべての入力がnullに戻ります。私がそれを取り出したら、それはうまくいく。コードイグナイタでデータベースにドロップダウン値を送信
<form name = "form1" id = "form1" method ="post"> <!--action="<?php echo base_url()."index.php/Admin/create_user"; ?>"-->
<?php echo validation_errors(); ?>
<label for="first_name" class = "labelForm">First Name:</label>
<input type="text" id="first_name" name="first_name" class = "input2">
<label for="last_name" class = "labelForm">Last Name:</label>
<input type="text" id="last_name" name="last_name" class = "input2">
<label for="username" class = "labelForm">Username:</label>
<input type="text" id="username" name="username" class = "input2" onblur="check_if_exists();">
<label for="password" class = "labelForm">Password:</label>
<input type="password" id="password" name="password" class = "input2" onblur="validatePassword();">
<label for="passconf" class = "labelForm">Password:</label>
<input type="password" id="passconf" name="passconf" class = "input2" onblur="checkPasswords();">
<label for="email" class = "labelForm">Email:</label>
<input type="text" id="email" name="email" class = "input2">
<!-- <label for="hospital" class = "labelForm">Hospital:</label>
<select name="product" class = "input2" id = "hospitals">
<option selected disabled hidden style='display: none' value=''></option>
<?php foreach($hospital_dropdown as $option){?>
<option id = "hospitals" name="hospitals" value="<?php $option->hospitalName;?>"> <?php print_r($option->hospitalName); ?> </option>
<?php }?>
</select>-->
<label for="hospitals" class = "labelForm">Hospital:</label>
<select name="product" class = "input2" id = "hospitals">
<?php foreach($hospital_dropdown as $index => $option):?>
<option id = "hospitals_<?=$index?>"
name="hospitals"
value="<?=$option->hospitalName;?>"
><?=$option->hospitalName;?></option>
<?php endforeach;?>
</select>
<button type="button" id = "new_user_submit">Add New User</button>
</form>
コントローラー:
function create_user(){
$this->load->model('User_model');
$password = $this->input->post('password');
$hash = $this->bcrypt->hash_password($password);
$data = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'username' => $this->input->post('username'),
'password' => $hash,
'class' => $this->input->post('userclass'),
'hospital' => $this->input->post('hospitals'),
'email' => $this->input->post('email'),
);
$this->User_model->create_user($data);
$username = $this->session->userdata('username');
$data['hospital_dropdown'] = $this->User_model->hospital_dropdown();
$data['main_content'] = 'admin';
$this->load->view('includes/admin/template', $data);
}
モデル:
function create_user($data){
$insert = $this->db->insert('users', $data);
return $insert;
}
私はそれを離れるとき、それは罰金提出するが、コントローラに病院の一部を取り出した場合は、すべてのフィールドが戻ってきますnullとして送信しません。 すべてのアイデア? ありがとう!
あなたが見ること渡す前にすべての値をvae_dumpなかった問題を解決すべきです? –
@FaisalMehmoodAwan値は正常にドロップダウンメニューに追加されました。ただデータベースに追加するだけで問題になります。 – user