我想根據用戶登錄禁用我的下拉菜單。 我在會話中存儲用戶類型。如何根據用戶登錄啓用禁用下拉菜單?
現在管理員創建用戶。然後該用戶可以登錄並編輯他的詳細信息。
我想只允許某些字段被該用戶編輯。
就像我不想讓他編輯他的user_type。
現在,如果我從我的表單字段中刪除它們會出現數據在mysql中截斷的錯誤。如果我通過html禁用它,它顯示相同的錯誤。
請幫我
的是控制器代碼:
public function edit ($id = NULL)
{
$user_type = $this->session->userdata('user_type');
if($user_type =="admin")
{
if ($id)
{
$this->data['user'] = $this->user_m->get($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
// Set up the form
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE)
{
$data = $this->user_m->array_from_post(array('emp_id','name','last_name','email','password','phone','gender','designation','user_type','blood_group','date_birth','status','address'));
if(!empty($data['password']))
{
$data['password'] = $this->user_m->hash($data['password']);
} else {
// We don't save an empty password
unset($data['password']);
}
$key=$this->user_m->save($data, $id);
redirect('admin/user/index');
}
}
// Load the view
$this->data['subview'] = 'admin/users/edit';
$this->load->view('admin/_layout_main', $this->data);
}
elseif($user_type=="employee")
{
if ($id)
{
$this->data['user'] = $this->user_m->get_emp($id);
count($this->data['user']) || $this->data['errors'][] = 'User could not be found';
$rules = $this->user_m->rules_admin;
$id || $rules['password']['rules'] .= '|required';
$this->form_validation->set_rules($rules);
// Process the form
if ($this->form_validation->run() == TRUE)
{
$data = $this->user_m->array_from_post(array('emp_id','name','last_name','email','password','phone','gender','designation','user_type','blood_group','date_birth','status','address'));
//$data['password'] = $this->user_m->hash($data['password']);
if(!empty($data['password']))
{
$data['password'] = $this->user_m->hash($data['password']);
} else {
// We don't save an empty password
unset($data['password']);
}
$id = $this->session->userdata('id');
$this->user_m->save($data, $id);
redirect('admin/user/index');
}
}
// Load the view
$this->data['subview'] = 'employee/profile/edit';
$this->load->view('employee/_layout_main', $this->data);
}
else
{
echo "You Seem To Be Lost";
}
}
編輯視圖
<h3><?php echo empty($user->id) ? '<i class="glyphicon glyphicon-user"></i> Add a User' : 'Edit User ' . $user->name; ?></h3>
<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<table class="table">
<tr>
<td>Employoee ID</td>
<td><?php echo form_input('emp_id', set_value('emp_id', $user->emp_id)); ?></td>
</tr>
<tr>
<td>Name</td>
<td><?php echo form_input('name', set_value('name', $user->name)); ?></td>
</tr>
<tr>
<td>Last Name</td>
<td><?php echo form_input('last_name', set_value('last_name', $user->last_name)); ?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo form_input('email', set_value('email', $user->email)); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_password('password'); ?></td>
</tr>
<tr>
<td>Phone</td>
<td><?php echo form_input('phone', set_value('phone', $user->phone)); ?></td>
</tr>
<tr>
<td>Gender</td>
<td><?php echo form_dropdown('gender', array('Male' => 'Male', 'Female' => 'Female'), $this->input->post('gender') ? $this->input->post('gender') : $user->gender); ?></td>
</tr>
<tr>
<td>Designation</td>
<td><?php echo form_input('designation', set_value('designation', $user->designation)); ?></td>
</tr>
<tr>
<td>User Type</td>
<td><?php echo form_dropdown('user_type', array('admin' => 'admin', 'employee' => 'employee','support_staff'=>'support_staff'), $this->input->post('user_type') ? $this->input->post('user_type') : $user->user_type); ?></td>
</tr>
<tr>
<td>Blood Group</td>
<td><?php echo form_input('blood_group', set_value('blood_group', $user->blood_group)); ?></td>
</tr>
<tr>
<td>Date Of Birth</td>
<td><?php echo form_input('date_birth', set_value('date_birth', $user->date_birth)); ?></td>
</tr>
<tr>
<td>Status</td>
<td><?php echo form_dropdown('status', array('Active' => 'Active', 'Inactive' => 'inactive', 'Delete' => 'delete'), $this->input->post('status') ? $this->input->post('status') : $user->status); ?></td>
</tr>
<tr>
<td>Address</td>
<td><?php echo form_textarea('address', set_value('address', $user->date_birth)); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Save', 'class="btn btn-primary"','onClick="image()"'); ?></td>
</tr>
</table>
<script>
$(function(){
$('#spinnerInput').spinner();
});
</script>
<?php echo form_close();?>
我建議適當縮進/格式代碼,如果你希望有人幫你 – DonCallisto
@DonCallisto是的,我會編輯 – Rajan