When verifying the mobile phone, it will jump to the registration page without any prompts
The previous email address and user name can be verified normally
王先生2019-11-06 11:54:51
Solved, it turned out that the name attribute setting on the registration page was wrong
王先生2019-11-06 09:38:48
There is too much content on the registration page, and it seems that it cannot be posted.
The registration page is exactly the same as what the teacher wrote
王先生2019-11-06 09:15:09
Controller
namespace app\index\controller;
use app\common\controller\Base;
use think\facade\Request;
use app\common\model\ User as UserModel;
class User extends Base
{
//Registration page
public function register()
{
$this->assign('title','User Register');
return $this->fetch();
}
//Process the registration information submitted by the user
public function insert()
{
If (request :: isajax ())
{
/**
* Use models to create data
#&*/##// Verification data
$ data = request :: Post (); // Data
$rule= 'app\common\validate\User';//Customized validation rules
$res=$this->validate($data,$rule);//Start validating data
’ ’ s ’ s ’ ’ s ’ ’ s ’ ’ s ’ ’ s ’ t 1 ];
}
Else
{
// If the data is correct
if (usermodel :: create ($ data))
{
Return ['Status' = & GT ;1,'message'=>'Congratulations, the registration is successful'];
}
else
‐ ‐ ‐ } ‐ ‐ ‐ ‐‐ '=>'Register Failure, please check '];
}
}
}
Else
{
$ this-& gt error ("" Request Type Error ",' Register ') ;
}
}
}
王先生2019-11-06 09:14:40
Validation rules namespace app\common\validate\User.php:
namespace app\common\validate;
use think\Validate;
class User extends Validate
{
/**
* Current validation rules
* @var array
*/
protected $rule = [
/**
* Another way of writing:
* * 'name|Username'=>'require|length:5,20|chsAlphaNum',
* 'email|Mailbox'=>'require|email |unique:zh_user',
* 'password|password'=>'require|alphaNum|length:6,20|confirm',
* 'mobile|手机'=>'require|mobile|unique :zh_user|number'
*/
'name|username'=>[
'require'=> 'require',
'length'=>'5,20',
'chsAlphaNum'=>'chsAlphaNum',//Only Chinese characters, characters and numbers are allowed
],
' email|Mailbox'=>[
'require'=>'require',
'unique'=>'zh_user',//This field value is unique in the zh_user table email'=>'email',
],
‐ ’ ’ ’ s ’ s ’ being ',
'unique'=>'zh_user',//This field value is unique in the zh_user table
'number'=>'number',
],
'password | Password '= & gt; [
' requine '= & gt;' reques,
'alphaanum' = & gt; 'alphaum', // Only allow letters plus numbers
'length' = & gt; ' 6,20',//Length limit
'confirm'=>'confirm',//Automatically perform equality verification with the password_confirm field
#