小程序表單提交

< form bindsubmit= 'formSubmit'>
< view >用戶名:
< input type= 'text' name= "username" value= '' placeholder= '請輸入您的姓名' / >
</ view >
< view >手機:
< input type= 'number' name= "tel" value= '' placeholder= '請輸入您的手機號' / >
</ view >

< view >
身份證:
< input type= 'idcard' name= "idcard" value= '' placeholder= '請輸入您的身份證號碼' / >
</ view >

< view >級別:
< radio-group name= "rank">
< label >
< radio value= "chuji" / >初級 </ label >
< label >
< radio value= "zhongji" checked= 'checked' / >中級 </ label >
< label >
< radio value= "gaoji" / >高級 </ label >
</ radio-group >
</ view >
< button form-type= 'submit'>保存 </ button >
</ form >

 

let app = getApp();
Page({
data: {
inputValue: ''
},
onLoad: function() {

},
formSubmit: function(e) {
console.log(e.detail.value)
console.log(e.detail.value.username)
console.log(e.detail.value.tel)
console.log(e.detail.value.idcard)
console.log(e.detail.value.rank)
var that = this;
var username = e.detail.value.username;
var tel = e.detail.value.tel;
var idcard = e.detail.value.idcard;
var rank = e.detail.value.rank;
if (!(idcard.length === 15 || idcard.length === 18)) {
wx.showToast({
title: '請輸入15或18位數身份證號碼',
duration: 2000
})
} else {
wx.request({
method: "POST",
url: "",
data: {
'username': username,
'tel': tel,
'idcard': idcard,
'rank': rank
},
header: {
'content-type': 'application/json'
},
success: function(res) {
wx.showToast({
title: '保存成功',
duration: 2000
})
}
})

}

}

})
相關文章
相關標籤/搜索