API教程

了解最新公司动态及行业资讯

当前位置:首页>新闻资讯>API教程
全部 24 小程序教程 7 API教程 13 常见问题 4

自定义表单form

时间:2023-09-09   访问量:1008


接口名称小程序自定义表单
接口标识:form
接口url:https://你的网站/api.php/index/form
接口参数

字段名称字段说明类型必填备注
fid表单idnum必填
type操作类型string可不填可选参数:post/提交表单、list/读取列表
num数量num可不填调用数量,默认10,为空则按照分页调用


type不同所需参数也不同
1、当type=post时候,提交表单
此时除了必须的type之外,其他的参数需要和你的后台参数类型相同

2、当type=list时,获取对应表单的内容列表

字段名称字段说明类型必填备注
fid表单idnum必填
type操作类型string必填可选参数:post/提交表单、list/读取列表、view/阅读;默认:post
num数量num可不填调用数量,默认10,为空则按照分页调用
pagesize自定义分页大小num可不填默认后台设置的页面大小
order排序string可不填默认:"id desc";该接口暂无开放

3、当type=view时候 暂未开启

字段名称字段说明类型必填备注
fd表单idnum必填
type操作类型string必填可选参数:post/提交表单、list/读取列表、view/阅读;默认:post
id内容IDnum必填(若该内容为未审核内容则直接返回错误信息)


小程序参考代码:

code腾石建站

  1. <form bindsubmit="formSubmitHandle"

  2.         <view class='form_input'

  3.               <input placeholder="请填写您的姓名" value='{{name}}' name='name' /> 

  4.         </view> 

  5.         <view class='form_input'

  6.               <input type='digit' placeholder="请填写电话" name='phone' value='{{phone}}' auto-focus/> 

  7.         </view> 

  8.         <view class='form_input'

  9.               <input type='text' placeholder="请填写QQ或邮箱" name='qq' /> 

  10.         </view> 

  11.         <view class='form_input'

  12.           <checkbox-group class="checkbox-group" name='xuqiu'

  13.               <checkbox value="网站建设" checked/>网站建设</checkbox> 

  14.               <checkbox value="域名空间" />域名空间</checkbox> 

  15.               <view class="c"></view> 

  16.               <checkbox value="网站改版" />网站改版</checkbox> 

  17.                <checkbox value="小程序开发" />小程序开发</checkbox> 

  18.           </checkbox-group> 

  19.         </view> 

  20.         <input type='text' name='fid' value="1" hidden='{{true}}'/> 

  21.         <view class='form_input'

  22.               <textarea class='form_textarea' name="content" placeholder="留言内容" /> 

  23.         </view> 

  24.         <view class="c"></view> 

  25.         <view class="btn-area"

  26.            <button form-type="submit">提交留言</button> 

  27.         </view> 

  28.     </form> 

小程序js代码:

code腾石建站

  1. formSubmitHandle: function (e) { 

  2.         console.log(e) 

  3.         var that = this 

  4.         /*复选框整合*/ 

  5.         var xuqiu = ''

  6.         for (var i in e.detail.value.xuqiu) { 

  7.             xuqiu += e.detail.value.xuqiu[i] + ','

  8.         } 

  9.  

  10.         var that = this

  11.         if (e.detail.value.name == '') { 

  12.             e.detail.value.name = '匿名' 

  13.         } 

  14.         if (e.detail.value.phone.length == 0) { 

  15.             swan.showModal({ 

  16.                 content: '电话不能为空'

  17.                 confirmText: '确定'

  18.                 cancelText: '取消' 

  19.             }); 

  20.         } else if (e.detail.value.content.length == 0) { 

  21.             swan.showModal({ 

  22.                 content: '内容不能为空'

  23.                 confirmText: '确定'

  24.                 cancelText: '取消' 

  25.             }); 

  26.         } else { 

  27.             swan.request({ 

  28.                 url: app.globalData.api + "form"

  29.                 data: { 

  30.                     fid: e.detail.value.fid,//必填 

  31.                     name: '【百度】' + e.detail.value.name,//区分正常留言,可以去掉 

  32.                     phone: e.detail.value.phone, 

  33.                     qq: e.detail.value.qq, 

  34.                     xuqiu: xuqiu, 

  35.                     content: e.detail.value.content, 

  36.                     type: 'post'

  37.                     aid: app.globalData.aid//必填 

  38.                 }, 

  39.                 method: 'POST'

  40.                 header: { 

  41.                     'content-type''application/x-www-form-urlencoded'

  42.                     'x-appsecret': app.globalData.appsecret 

  43.                 }, 

  44.                 success: function (res) { 

  45.                     console.log(res) 

  46.                     if (res.data.status == 'ok') { 

  47.                         swan.showToast({ 

  48.                             title: '留言成功!!'

  49.                             icon: 'success'

  50.                             duration: 1500, 

  51.                             success: function () { 

  52.                                 setTimeout(function () { 

  53.                                     swan.navigateBack(); 

  54.                                 }, 2000) 

  55.                             } 

  56.                         }) 

  57.  

  58.                     } else { 

  59.                         swan.showToast({ 

  60.                             title: '留言失败,请重新提交!!'

  61.                             icon: 'warn'

  62.                             duration: 1500 

  63.                         }) 

  64.                     } 

  65.                     setTimeout(function () { 

  66.                         swan.hideToast() 

  67.                     }, 2000) 

  68.                 } 

  69.             }) 

  70.         } 

  71.     }, 

小程序获取表单内容列表代码:

code腾石建站

  1. get_msglist(diyid) { 

  2.         swan.request({ 

  3.             url: app.globalData.api + "form"

  4.             data: { 

  5.                 fid: fid,//必填 

  6.                 type: 'list'

  7.                 aid: app.globalData.aid//必填 

  8.             }, 

  9.             method: 'POST'

  10.             header: { 

  11.                 'content-type''application/x-www-form-urlencoded'

  12.                 'x-appsecret': app.globalData.appsecret 

  13.             }, 

  14.             success: function (res) { 

  15.                 console.log(res) 

  16.             } 

  17.         }) 

  18.     }, 


上一篇:用户授权登录member

下一篇:公司信息company

在线咨询

点击这里给我发消息 售前咨询专员

点击这里给我发消息 售后服务专员

在线咨询

免费通话

24小时免费咨询

请输入您的联系电话,座机请加区号

免费通话

微信扫一扫

微信联系
返回顶部