wxml:
<view class='info' wx:if="{{infoCeng}}">
<view class='infobox'>
<form bindsubmit='searchBox'>
<view class='listinfo'>
<text>姓名:</text>
<input type='text'
name="myname" id='name' class='inputinfo'></input>
</view>
<view class='listinfo'>
<text>電話:</text>
<input type='tel'
name="tel" id='tel' class='inputinfo'></input>
</view>
<button type='submit' id='tijiao'
form-type='submit'>提交</button>
</form>
</view>
</view>
js:
searchBox:function(e){
var that=this;
that.setData({
showPage:true,
})
nameUser = e.detail.value.myname;
telUser = e.detail.value.tel;
console.log(nameUser + telUser)
if (nameUser=="") {
wx.showToast({
title: '請輸入您的姓名',
duration:1000,
icon:"none"
})
return;
} else if (
!/1[3-9]\d{9}/.test(telUser)) {
wx.showToast({
title: '請正確輸入您的手機號',
duration: 1000,
icon: "none"
})
return;
}else{
wx.login({
success: function (lgres){
wx.request({
url: 'https://xxxxxxx.com/Client.aspx',
method: 'POST',
data: {
ModuleName: "WX_BJML",//空間名 接口文檔里每個接口會有標明 必填
MethodName: "SubInfo",//方法名 接口文檔里每個接口會有標明 必填
Guid: "",//令牌獲取到的值 必填(獲取令牌接口例外)
Token: "",//使用令牌md5加密生成的token值 必填(獲取令牌接口例外)
Data: {
code: lgres.code,// lgres.code,//只查某個人的 不填不限制
name: nameUser,//姓名
tel: telUser,
}
},
header: {
'content-type': 'application/json'
},
success: function (res1) {
console.log("信息提交成功");
console.log(res1)
wx.showToast({
title: '禮品領取成功',
duration:1500,
icon: "none"
})
that.setData({
infoCeng:false,
linqushow:false,
monery:"您已成功領取禮品:"+liping,
});
},
fail:function(){
},
complete:function(){
that.setData({
showPage: false,
})
}
})
}
})
}
},
更新於2018-3-16上午
上面的代碼中是正常的情況下,不會發展其他的額外需求下可以那樣書寫;
若是后期客戶需要推送模板消息時,那我們前端的代碼就要有所改變
1.將form標簽放在頁面的最外層
2.form標簽將組件內的用戶輸入的<switch/><input/><checkbox/><slider/><radio/><picker/>
3.當點擊<form/>表單中formType為submit的<button/>組件時,會將表單組建中加上name來作為Key.
wxml:
<form bindsubmit="formsubmit">
<view class='info' wx:if="{{infoCeng}}">
<view class='infobox'>
<view class='listinfo'>
<text>姓名:</text>
<input type='text'
name="myname" id='name' class='inputinfo'></input>
</view>
<view class='listinfo'>
<text>電話:</text>
<input type='tel'
name="tel" id='tel' class='inputinfo'></input>
</view>
<button type='submit' id='tijiao'
form-type='submit'>提交</button>
</view>
</view>
</form>
formsubmit:function(e){
console.log('form發生了submit事件,攜帶數據為:', e.detail.value)
console.log('form返回formId,攜帶數據為:', e.detail.formId);
//下面的內容更上面的一樣
}