微信小程序 form表單提交


html:{

<view class='tj'>
<form bindsubmit="formSubmit">
<view class='title'>丫丫上門服務</view>
<view class='box'><label>姓名:</label> <input type='text' name='xm' value='' /> <view class='clear'></view></view>
<view class='box'><label>聯系方式:</label> <input type='text' name='lxfs' value='' /> <view class='clear'></view> </view>
<view class='box'><label>需求:</label> <input type='text' name='xq' value='' /> <view class='clear'></view></view>
<view class='box'><label>小區名字:</label> <input type='text' name='xqmz' value='' /> <view class='clear'></view></view>
<button formType="submit">提交</button>
</form>
</view>

}

index.js代碼

Page({
formSubmit: function (e) {
// var info = e.detail.value
if (e.detail.value.xm.length == 0 || e.detail.value.xq.length == 0 || e.detail.value.lxfs.length == 0 || e.detail.value.xqmz.length == 0) {

wx.showModal({

title: '姓名或聯系方式或需求或小區名字不得為空!',
content:'很棒棒喲',

})

} else if (e.detail.value.lxfs.length != 11){
wx.showToast({

title: '請輸入11位手機號碼!',

icon: 'loading',

duration: 1500

})

setTimeout(function () {

wx.hideToast()

}, 2000)


}else{
wx.request({
url: app.globalData.http + '/Wechat/apply', //僅為示例,並非真實的接口地址
header: {
'content-type': 'application/x-www-form-urlencoded' // 默認值
},
method:'POST',
data:{xm:e.detail.value.xm,lxfs:e.detail.value.lxfs,xq:e.detail.value.xq,xqmz:e.detail.value.xqmz},
success: function (res) {
if (res.data.status == 0) {

wx.showToast({

title: res.data.info,

icon: 'loading',

duration: 1500

})

} else {

wx.showToast({

title: res.data.info,//這里打印出登錄成功

icon: 'success',

duration: 1000

})

}

}
})
}

},
如有不懂可查看原網站http://www.jb51.net/article/102875.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM