view内容:
用户名
validation->username_error; ?>密码
validation->password_error; ?>确认密码
validation->passconf_error; ?>
controller内容:
$this->load->library('validation');$this->load->helper('form');$rules['username'] = "trim|required|min_length[5]|max_length[16]|xss_clean|callback_username_check";$rules['password'] = "trim|required|matches[passconf]|md5";$rules['passconf'] = "trim|required";$rules['email'] = "trim|required|valid_email|callback_email_check";$this->validation->set_rules($rules);$fields['username'] = '用户名';$fields['password'] = '密码';$fields['passconf'] = '密码确认';$fields['email'] = '邮箱地址';$this->validation->set_fields($fields);if ($this->validation->run() == FALSE){ $this->load->view('user/reg_view');}else{ //调用这个函数保存数据到数据库 $this->user_model->reg(); $this->load->view('user/reg_suc_view');}
model内容:
$activation_key = md5(uniqid() + time());$data = array( 'username' => $this->input->post('username'), 'password' => $this->input->post('password'), 'email' => $this->input->post('email'), 'registered_date' => time(), 'activation_key' => $activation_key, 'status'=>0, 'level'=>0, 'reserve_times'=>0, 'credit'=>0,);$this->db->insert($this->config->item('db_prefix').'user', $data);
碰到类似的表单提交的功能,直接ctrl+c、ctrl+v,改改就能用。