public function edit_profile(){
$logged_in_user = $this->session->userdata('logged_in');
$data['images_url'] = $this->config->item('images_url');
$data['cdn_url'] = $this->config->item('cdn_url');
$data['reminder'] = $this->config->item('reminder');
$data['current_module'] = "ess";
$data['user_details'] = $this->ess->get_user_details($logged_in_user['user_id']);
$this->load->view("header", $data);
$this->load->view("leftbar", $data);
$this->load->view("ess/ess_edit_profile");
$this->load->view("footer", $data);
if($this->input->post('submit')){
$post_data = $this->input->post();
$this->form_validation->set_rules('full_name','Full Name','required|trim|xss_clean');
$this->form_validation->set_rules('email','Email','required|trim|valid_email');
$this->form_validation->set_rules('blood_group','Blood Group','max_length[2]');
$this->form_validation->set_rules('phone','Phone','required|trim|xss_clean');
$this->form_validation->set_rules('address','Address','required|xss_clean|max_length[100]');
$this->form_validation->set_rules('designation','Designation','required|xss_clean');
$this->form_validation->set_rules('emergency_name','Emergency Name','required|xss_clean');
$this->form_validation->set_rules('emergency_number','Emergency Number','required|xss_clean');
$this->form_validation->set_rules('next_of_kin','Next of Kin','trim|xss_clean');
if($this->form_validation->run() === true){
// update data
} else {
$this->load->view("ess/ess_edit_profile");
}
}
}
以上是我的控制器的功能,它在输入字段中加载带有数据库填充值的编辑配置文件视图。现在,在完成编辑后提交表单时,它将转到edit_profile()
函数中的验证过程。我故意运行false验证功能以进行检查。现在,如果验证运行=== false我再次加载了ess_edit_profile
视图,但验证消息没有出现。表单字段也填充了我通过set_value()
函数
下面是我如何显示带有数据库数据的表单字段
<td>
<label for="full_name">Full Name</label>
<input style="width: 300px;" type="text" name="full_name" id="full_name" value="<?php echo set_value('full_name',$user_details[0]->ui_full_name); ?>" />
<?php echo form_error('full_name', '<span class="alert">', '</span>'); ?>
</td>
答案 0 :(得分:0)
尝试删除其他部分,然后尝试
if($this->form_validation->run() === true){
// update data
}
$this->load->view("ess/ess_edit_profile");
答案 1 :(得分:0)
请使用set_value
功能设置元素值
喜欢这个
<input type="text" name="name" value="<?php echo set_value("name", $database_name)?>"/>
在控制器
中$this->form_validation->set_rules('name','Edit name','trim|xss_clean|required');
如果不需要该值,则还设置验证规则trim
$this->form_validation->set_rules('name','Edit name','trim');