This article describes an example of THINKPHP5 using Bootstrapvalidator for an asynchronous verification mailbox, which is shared 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 ',//after validation fails, the Submit button is still optional fields: {email: {message: ' Username verification failed ',//default Verbose:false, Validators: {notempty: {message: ' Mailbox cannot be empty '}, EmailAddress: {mess Age: ' Email address is malformed '}, Remote: {URL: '/ajax_email ', message: ' This mailbox is already registered ', Typ E: "Post", DataType: ' JSON ', data: {//= the value of the input box is passed by default}, delay:500 ,//Delay Effect},}}, Password: {validators: {notempty: {message: ' Email address not can be empty '}, Stringlength: {min:6, max:18, message: ' Long user nameThe degree must be between 6 and 18 bits '},},}, Password2: {validators: {notempty: {message: ' Confirm password cannot be empty '}, identical: {field: ' Password ', message: ' Two times password must be identical '} }}, username:{validators: {notempty: {message: ' User name 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 can be empty, it replaces the message property of the JS authentication echo json_encode ([' Valid ' =>false, ' Message ' = = ' Verification code is incorrect ']); }
JS verification several points of attention
Verbose:false, on behalf of JS authentication legal and then asynchronous background verification, so as to reduce server pressure
Data: {}, the value of the input box is passed by default, so it is generally not necessary to write the property, or to be empty
Background attention Point
Note not return but Echo
Returns the JSON format {' Valid ': true[, ' message ': ' Validation succeeded ']}