新聞中心
- form 表單
- 屬性說(shuō)明
- report-type 有效值
- report-type 為 subscribe 時(shí),event.detail.formId 說(shuō)明
- report-type 為 subscribe 時(shí),status 和 message 具體值
- 示例
- 代碼示例 1:普通表單
- 代碼示例 2:模板類型表單
- 屬性說(shuō)明
form 表單
解釋:表單,將 form 組件內(nèi)用戶輸入 / 選擇的、、、、、提交。當(dāng)表單中 form-type 為 submit 時(shí),點(diǎn)擊的組件會(huì)將表單組件中的 value 值進(jìn)行提交,需要在表單組件中加上 name 來(lái)作為 key 。
Web 態(tài)說(shuō)明:在 Web 態(tài)下,由于瀏覽器的限制,部分系統(tǒng)信息無(wú)法獲取,故暫不支持表單類、訂閱類模板消息。

創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)、斗門網(wǎng)絡(luò)推廣、成都小程序開(kāi)發(fā)、斗門網(wǎng)絡(luò)營(yíng)銷、斗門企業(yè)策劃、斗門品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)建站為所有大學(xué)生創(chuàng)業(yè)者提供斗門建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
屬性說(shuō)明
| 屬性名 | 類型 | 默認(rèn)值 | 必填 | 說(shuō)明 | 最低版本 |
|---|---|---|---|---|---|
| report-submit | Boolean | false | 否 | 是否返回 formId 用于發(fā)送模板消息(工具上 formId 為‘’,請(qǐng)?jiān)谡鏅C(jī)上測(cè)試),訂閱消息詳細(xì)說(shuō)明請(qǐng)參考訂閱消息接入 | 1.12 低版本請(qǐng)做兼容性處理 |
| report-type | String | ‘default’ | 否 | 模板消息的類型,report-submit 為 true 時(shí)填寫有效 取值:default / subscribe | 3.105.3 低版本請(qǐng)做兼容性處理 |
| template-id | String/Array. | 否(report-type 為 subscribe 時(shí)必填) | 發(fā)送訂閱類模板消息所用的模板庫(kù)標(biāo)題 ID ,可通過(guò) getTemplateLibraryList 獲取 當(dāng)參數(shù)類型為 Array 時(shí),可傳遞 1~3 個(gè)模板庫(kù)標(biāo)題 ID | 3.105.3(String 類型) 3.170.1(Array 類型) 低版本請(qǐng)做兼容性處理 | |
| subscribe-id | String | 否(report-type 為 subscribe 時(shí)必填) | 發(fā)送訂閱類模板消息時(shí)所使用的唯一標(biāo)識(shí)符,內(nèi)容由開(kāi)發(fā)者自定義,用來(lái)標(biāo)識(shí)訂閱場(chǎng)景 注意:同一用戶在同一 subscribe-id 下的多次授權(quán)不累積下發(fā)權(quán)限,只能下發(fā)一條。若要訂閱多條,需要不同 subscribe-id | 3.105.3 低版本請(qǐng)做兼容性處理 | |
| bindsubmit | EventHandle | 否 | 攜帶 form 中的數(shù)據(jù)觸發(fā) submit 事件,event.detail = {value : {‘name’: ‘value’}, formId: ‘’, message: ‘’, status: ‘’},當(dāng) report-type 為 subscribe 時(shí),status 和 message 中返回用戶授權(quán)具體信息 | - | |
| bindreset | EventHandle | 否 | 表單重置時(shí)會(huì)觸發(fā) reset 事件 | - |
report-type 有效值
| 值 | 說(shuō)明 | web 態(tài)說(shuō)明 |
|---|---|---|
| default | 表單類模板消息 | Web 態(tài)不支持表單類模板消息,bindsubmit 回調(diào)參數(shù)中的 message 始終為“請(qǐng)求 formId 失敗”,status 始終為500105 |
| subscribe | 訂閱類模板消息,需要用戶授權(quán)才可發(fā)送 | Web 態(tài)不支持訂閱類模板消息,不會(huì)彈窗提示授權(quán),會(huì)降級(jí)調(diào)起百度 App。bindsubmit 回調(diào)參數(shù)中的 message 始終為“請(qǐng)求 formId 失敗”,status 始終為500105 |
report-type 為 subscribe 時(shí),event.detail.formId 說(shuō)明
1. 當(dāng) template-id 為 String 時(shí)(基礎(chǔ)庫(kù) 3.105.3 開(kāi)始支持),event.detail 的 formId 為 String ,即此 template-id 所對(duì)應(yīng)的的 formId 。舉例如下:
- SWAN
- JS
Page({formSubmit(e) {// 此時(shí) formId 為 'BD0001-formId'(非真實(shí)數(shù)據(jù))swan.showModal({title: 'template-id 為 string',content: e.detail.formId});}});
2. 當(dāng) template-id 為 Array 時(shí)(基礎(chǔ)庫(kù) 3.170.1 開(kāi)始支持),event.detail 的 formId 為 Object ,其中對(duì)象的 key 為 template-id ,value 為其對(duì)應(yīng)的 formId 。舉例如下:
- SWAN
- JS
Page({data: {templateId: ['BD0001', 'BD0002']},formSubmit(e) {// 此時(shí) formId 為 {'BD0001': 'BD0001-formId', 'BD0002': 'BD0002-formId'}(非真實(shí)數(shù)據(jù))swan.showModal({title: 'template-id 為 Array',content: JSON.stringify(e.detail.formId)});}});
如果 Array 中的 template-id 超過(guò)三個(gè),返回的 formId 為空字符串,舉例如下:
- SWAN
- JS
Page({data: {templateId: ['BD0001', 'BD0002', 'BD0003', 'BD0004']},formSubmit(e) {// 此時(shí) formId 為 ''swan.showModal({title: 'template-id 超過(guò)三個(gè)',content: e.detail.formId});}});
如果 Array 中有重復(fù)的 template-id ,重復(fù)的 template-id 對(duì)應(yīng)的 formId 只返回一次,舉例如下:
- SWAN
- JS
Page({data: {templateId: ['BD0001', 'BD0001', 'BD0002']},formSubmit(e) {// 此時(shí) formId 為 {'BD0001': 'BD0001-formId', 'BD0002': 'BD0002-formId'}(非真實(shí)數(shù)據(jù))swan.showModal({title: '有重復(fù)的 template-id',content: JSON.stringify(e.detail.formId)});}});
注意:在提交 form 表單時(shí),將會(huì)彈出模板消息授權(quán)彈窗,用戶授權(quán)后才能在 event.detail 中獲取被授權(quán)模板消息的 formId 。
report-type 為 subscribe 時(shí),status 和 message 具體值
status 為 Number 類型,message 為 String 類型,當(dāng)用戶永久拒絕授權(quán)的時(shí)候,建議開(kāi)發(fā)者不要再展示訂閱消息授權(quán)面板入口。
| status | message |
|---|---|
| 500101 | 用戶永久拒絕授權(quán) |
| 500102 | 用戶單次拒絕授權(quán) |
| 500103 | 用戶取消授權(quán) |
| 500104 | 請(qǐng)求模板內(nèi)容失敗 |
| 500105 | 請(qǐng)求 formId 失敗 |
示例
跳轉(zhuǎn)編輯工具
在開(kāi)發(fā)者工具中打開(kāi)
在 WEB IDE 中打開(kāi)
掃碼體驗(yàn)
代碼示例
請(qǐng)使用百度APP掃碼
代碼示例 1:普通表單
- SWAN
- JS
bindreset="formReset">開(kāi)關(guān)選擇器 開(kāi)關(guān) 單項(xiàng)選擇器 單選項(xiàng)一 單選項(xiàng)二 多項(xiàng)選擇器 多選項(xiàng)一 多選項(xiàng)二 多選項(xiàng)三 滑塊選擇器 輸入框 提交表單
Page({formSubmit(e) {console.log('form發(fā)生了submit事件,攜帶數(shù)據(jù)為:', e.detail.value);swan.showModal({content: '數(shù)據(jù):' + JSON.stringify(e.detail.value),confirmText: '確定'});},formReset(e) {console.log('form表單發(fā)生了', e.type);}});
代碼示例 2:模板類型表單
在開(kāi)發(fā)者工具中打開(kāi)
在開(kāi)發(fā)者工具中打開(kāi)
在 WEB IDE 中打開(kāi)
- SWAN
- JS
report-submitreport-type="subscribe"template-id="BD0003"subscribe-id="8026"bindsubmit="reportFormSubmit"bindreset="reportFormReset">report-type為subscribe report-submitreport-type="default"bindsubmit="reportFormSubmit"bindreset="reportFormReset">report-type為default
Page({onLoad() {swan.showToast({title: '此組件需要登錄態(tài),請(qǐng)先點(diǎn)擊下方的按鈕登錄',icon: 'none'})},login(e) {// 此組件需要在登陸態(tài)下使用console.log('登錄信息:', e);if (e.detail.errCode === '10004') {swan.showToast({title: '用戶未登錄',icon: 'none'});return;}swan.showToast({title: '用戶登錄成功',icon: 'none'});},formSubmit(e) {swan.showModal({title: '表單數(shù)據(jù)',content: JSON.stringify(e.detail.message) + '/' +JSON.stringify(e.detail.status),confirmText: '確定',showCancel: false});}});
網(wǎng)站標(biāo)題:創(chuàng)新互聯(lián)百度小程序教程:form表單
本文路徑:http://www.5511xx.com/article/dhgspjo.html


咨詢
建站咨詢
