在驗證手機的時候,沒有任何提示就跳轉(zhuǎn)會注冊頁面了
問題描述
在驗證手機的時候,沒有任何提示就跳轉(zhuǎn)會注冊頁面了
前面的郵箱和用戶名可以正常驗證
問題解答
回答1:已解決,原來真的是注冊頁面的name屬性設(shè)置錯誤
回答2:注冊頁面的內(nèi)容太多,貌似貼不上來,
注冊頁面和老師的寫的一模一樣
回答3:控制器
namespace appindexcontroller;use appcommoncontrollerBase;use thinkfacadeRequest;use appcommonmodelUser as UserModel;class User extends Base{ //注冊頁面 public function register() {$this->assign('title','用戶注冊');return $this->fetch(); } //處理用戶提交的注冊信息 public function insert() {if(Request::isAjax()){ /** * 使用模型來創(chuàng)建數(shù)據(jù) */ //驗證數(shù)據(jù) $data= Request::post();//等到要驗證的數(shù)據(jù) $rule= 'appcommonvalidateUser';//自定義的驗證規(guī)則 $res=$this->validate($data,$rule);//開始驗證數(shù)據(jù) if(true !==$res) {//如果數(shù)據(jù)不正確,返回驗證信息return ['status'=>-1,'message'=>$res]; } else {//如果數(shù)據(jù)正確if(UserModel::create($data)){ return ['status'=>1,'message'=>'恭喜,注冊成功'];}else{ return ['status'=>0,'message'=>'注冊失敗,請檢查'];} }}else{ $this->error("請求類型錯誤", 'register');} }}
回答4:驗證規(guī)則namespace appcommonvalidateUser.php:
namespace appcommonvalidate;use thinkValidate;class User extends Validate{ /** * 當前驗證規(guī)則 * @var array */ protected $rule = [/** * 另一種寫法: * 'name|用戶名'=>'require|length:5,20|chsAlphaNum', * 'email|郵箱'=>'require|email|unique:zh_user', * 'password|密碼'=>'require|alphaNum|length:6,20|confirm', * 'mobile|手機'=>'require|mobile|unique:zh_user|number' */'name|用戶名'=>[ 'require'=>'require', 'length'=>'5,20', 'chsAlphaNum'=>'chsAlphaNum',//僅允漢字,字符和數(shù)字],'email|郵箱'=>[ 'require'=>'require', 'unique'=>'zh_user',//該字段值在zh_user表中是唯一性 'email'=>'email',],'mobile|手機'=>[ 'require'=>'require', 'mobile'=>'mobile', 'unique'=>'zh_user',//該字段值在zh_user表中是唯一性 'number'=>'number',],'password|密碼'=>[ 'require'=>'require', 'alphaNum'=>'alphaNum',//僅允許字母加數(shù)字 'length'=>'6,20',//長度限定 'confirm'=>'confirm',//自動與password_confirm字段進行相等驗證], ];}
回答5:貼代碼看下
