View content:
<?phpEchoForm_Open (' User/reg ');?> $this->validation->username;? > "size="/> <span id= "error_msg" ><?phpEcho $this->validation->username_error;?></span> Echo $this->validation->password_error;?></span> Echo $this->validation->passconf_error;?></span> $this->validation->email;? > "size="/> <span id= "error_msg" ><?phpEcho $this->validation->email_error;?></span> <div><input type= "Submit" value= "Submit"/></div > </form>
Controller content:
$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 '] = ' user name ';$fields[' password '] = ' password ';$fields[' passconf '] = ' Password confirmation ';$fields[' email '] = ' Email address ';$this->validation->set_fields ($fields);if($this->validation->run () = =FALSE){ $this->load->view (' User/reg_view ');}Else{ //Call this function to save the data to the database $this->user_model->Reg (); $this->load->view (' User/reg_suc_view ');}
Model content:
$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, ' credits ' =>0,);$this->db->insert ($this->config->item (' Db_prefix '). ' User ',$data);
Encountered similar form submission function, direct CTRL + C, CTRL + V, change can be used.
CodeIgniter Typical form-Submission validation code