菜单

Thinkphp5 an example of using bootstrapvalidator to asynchronously validate mailboxes

2017年11月22日 - PHPer

This paper introduces the example of thinkphp5 using bootstrapvalidator for asynchronous authentication mailbox, and share it with you as follows:

JS verification

/ * *

* Created by HONGXIN on 2017-10-23.

* /

$(function () {)

$(‘form’).BootstrapValidator ({)

Message:’This value is not valid’,

FeedbackIcons: {

Valid:’glyphicon glyphicon-ok’,

Invalid:’glyphicon glyphicon-remove’,

Validating:’glyphicon glyphicon-refresh’

},

Live:’disabled’/ / validation failed after the submit button is still optional state

Fields: {

Email: {

Message: ‘username verification failed’ / / default

Verbose: false,

Validators: {

NotEmpty: {

Message: ‘mailbox cannot be empty’

},

EmailAddress: {

Message: ’email address format is wrong

},

Remote: {

Url:’/ajax_email’,

Message: “this mailbox has been registered”,

Type: “post””,

DataType:’json’,

Data: {

Is the default input / / transfer box value

},

500 / / delay:, delay effect

},

}

},

Password: {

Validators: {

NotEmpty: {

Message: ‘mailbox address cannot be empty

},

StringLength: {

Min: 6,

Max: 18,

Message: ‘user name length must be between 6 and 18 bits’

},

},

},

Password2: {

Validators: {

NotEmpty: {

Message: ‘confirm password cannot be empty’

},

Identical: {

Field:’password’,

Message: ‘two passwords must be consistent

}

}

},

Username:{

Validators: {

NotEmpty: {

Message: ‘username cannot be empty’

},

StringLength: {

Min: 2,

Max: 8,

Message: ‘user name length must be between 2 and 8 bits’

}

}

}

}

});

});

TP5 processing

Public function ajax_email () {

The message / message attribute can be empty, it replaced the JS verification

Echo json_encode ([‘valid’=> false,’message’=> ‘incorrect verification code’]);

}

Several points of attention in JS verification

Verbose: false, which represents JS validation and then asynchronous background verification, reduces server pressure

Data: is the default input {}, the value of the transfer box, so generally do not write this property, or empty

Backstage attention point

Notice not return, but echo

Return to the JSON {‘valid’format: true[,’message’: ‘to verify the success of’]}

发表评论

电子邮件地址不会被公开。