Examples of WeChat applet form verification function and Applet Form Verification

Source: Internet
Author: User

Example of complete applet form verification function and example of Applet Form Verification

This example describes the form verification function of the applet. We will share this with you for your reference. The details are as follows:

Wxml

<Form bindsubmit = "formSubmit" bindreset = "formReset"> <input name = "name" class = "{whoClass = 'name '? 'Placeholderclass ': 'inputclass'} "placeholder =" Please fill in your name "type =" text "confirm-type =" next "focus =" {whoFocus = 'name '? True: false }} "bindblur =" nameBlurFocus "/> <radio-group name =" gender "bindchange =" radioChange "> <radio value =" 0 "checked/> Ms. <radio value = "1"/> SIR </radio-group> <input name = "mobile" class = "{whoClass = 'mobile '? 'Placeholderclass ': 'inputclass'} "type =" number "maxlength =" 11 "placeholder =" Enter your mobile phone number "bindblur =" mobileBlurFocus "focus =" {whoFocus = 'mobile '? True: false }}"/> <input name = "company" class = "{whoClass = 'company '? 'Placeholderclass': 'inputclass'} "placeholder =" company name "type =" text "confirm-type =" next "focus =" {whoFocus = 'company '? True: false }}"/> <input name = "client" class = "{whoClass = 'client '? 'Placeholderclass': 'inputclass'} "placeholder =" binding customer "type =" text "confirm-type =" done "focus =" {whoFocus = 'client '? True: false }}"/> <button formType = "submit"> submit </button> </form> <loading hidden = "{submitHidden}"> submitting... </loading>

App. js

import wxValidate from 'utils/wxValidate'App({  wxValidate: (rules, messages) => new wxValidate(rules, messages)})

News. js

Var appInstance = getApp () // Form Verification initialization onLoad: function () {this. wxValidate = appInstance. wxValidate ({name: {required: true, minlength: 2, maxlength: 10,}, mobile: {required: true, tel: true,}, company: {required: true, minlength: 2, maxlength: 100,}, client: {required: true, minlength: 2, maxlength: 100, }}, {name: {required: 'Enter your name',}, mobile: {required: 'enter your mobile phone number',}, company :{ Required: 'Enter the company name',}, client: {required: 'Enter the bound customer',})}, // form submission formSubmit: function (e) {// submit the error description if (! This. wxValidate. checkForm (e) {const error = this. wxValidate. errorList [0] // '$ {error. param}: $ {error. msg} 'wx. showToast ({title: '$ {error. msg} ', image:'/pages/images/error.png ', duration: 2000}) return false} this. setData ({submitHidden: false}) var that = this // submit wx. request ({url: '', data: {Realname: e. detail. value. name, Gender: e. detail. value. gender, Mobile: e. detail. value. mobile, Company: e. detail. value. company, client: e. detail. value. client, Identity: appInstance. userState. identity}, method: 'post', success: function (requestRes) {that. setData ({submitHidden: true}) appInstance. userState. status = 0 wx. navigateBack ({delta: 1})}, fail: function () {}, complete: function (){}})}

Click here for the WxValidate. js FileDownload from this site.

I hope this article will help you develop small programs.

Related Article

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.