TP5 example of how to use Bootstrapvalidator for asynchronous verification of mailboxes

Source: Internet
Author: User
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

    1. Verbose:false, on behalf of JS authentication legal and then asynchronous background verification, so as to reduce server pressure

    2. 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

    1. Note not return but Echo

    2. Returns the JSON format {' Valid ': true[, ' message ': ' Validation succeeded ']}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.