|
楼主 |
发表于 2018-7-14 09:39:25
|
显示全部楼层
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Register extends CI_Controller{
public function index()
{
/*
*注册动作
*/
//载入验证类
$this->load->library('form_validation');
//设置规则
$this->form_validation->set_message('matches','两次密码不一致');
$this->form_validation->set_message('is_unique','此手机号已被注册');
$this->form_validation->set_rules('UsePho','手机号','required|min_length[11]|max_length[11]|is_unique[user.UsePho]');
$this->form_validation->set_rules('UseNam','账号','required|min_length[5]|max_length[11]|is_unique[user.UseNam]',array('is_unique'=>'此账号已被注册'));
$this->form_validation->set_rules('UseKey','密码','required|min_length[6]|max_length[11]');
$this->form_validation->set_rules('PassWo','确认密码','required|min_length[6]|max_length[11]|matches[UseKey]');
//执行验证
$status = $this->form_validation->run();
// var_dump($status);die;
if($status){
// var_dump($status);die;
$data = array(
'UsePho'=>$this->input->post('UsePho'),
'UseNam'=>$this->input->post('UseNam'),
'UseKey'=>$this->input->post('UseKey'),
);
$this->load->model('register_model','reg');
$this->reg->add($data);
success('login/index','注册成功,确认返回主界面');
}else{
error('注册失败');
$this->load->helper('form');
$this->load->view('login.html');
}
}
}
?>
如果没有error函数的话,错误时输入框下面会有错误提示的,有这个函数的话报错后错误提示就没了。 |
|