【声明】关于六久阁私自出售我公司dedecms小程序插件声明
发布时间:2019-08-22 10:54:12查看:0自定义表单diyform 
接口名称:小程序自定义表单
接口标识:diyform
接口url:https://你的网站/api/index.php?action=diyform&type=post
接口参数
字段名称 字段说明 类型 必填 备注
diyid 表单id num 必填  
type 操作类型 string 可不填 可选参数:post/提交表单、list/读取列表、view/阅读;默认:post
num 数量 num 可不填 调用数量,默认10,为空则按照分页调用

type不同所需参数也不同
1、当type=post时候,提交表单
此时除了必须的aid、type之外,其他的参数需要和你的后台参数类型相同
2、当type=list时,获取对应表单的内容列表
字段名称 字段说明 类型 必填 备注
diyid 表单id num 必填  
type 操作类型 string 必填 可选参数:post/提交表单、list/读取列表、view/阅读;默认:post
num 数量 num 可不填 调用数量,默认10,为空则按照分页调用
pagesize 自定义分页大小 num 可不填 默认后台设置的页面大小
order 排序 string 可不填 默认:"id desc";该接口暂无开放
3、当type=view时候
字段名称 字段说明 类型 必填 备注
diyid 表单id num 必填  
type 操作类型 string 必填 可选参数:post/提交表单、list/读取列表、view/阅读;默认:post
id 内容ID num 必填 (若该内容为未审核内容则直接返回错误信息)

小程序参考代码:
  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='diyid' 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代码:
  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 + "action=diyform"
  29.                 data: { 
  30.                     diyid: e.detail.value.diyid,//必填 
  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.     }, 
小程序获取表单内容列表代码:
  1. get_msglist(diyid) { 
  2.         swan.request({ 
  3.             url: app.globalData.api + "action=diyform"
  4.             data: { 
  5.                 diyid: diyid,//必填 
  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.     }, 

你在使用自定义表单接口的时候如果遇到什么问题,请随时与我们交流QQ:2863868475

注意事项

(1)由于dedecms自带的安全检测的防注入代码,会造成表单无法提交提示:Safe Alert: Request Error step 2!,此时需要对dedecms源码做个修改即可
打开include下的dedesql.class.php找到构造函数
  1. function __construct($pconnect=false,$nconnect=true
  2. $this->isClose = false
  3. $this->safeCheck = true;//改成FALSE即可 
  4. if($nconnect) 
  5. $this->Init($pconnect); 

【注意】最近网上有人公开出售我的源码,特做此声明:
(1)本站是dedecms小程序插件唯一教程官网,购买插件请联系QQ:2863868475;
(2)只有在本站购买的小程序插件会提供升级、维护和技术支持;
(3)在第三方网站购买的源码出现任何不可预测的情况与本站无关。
(4)作者未授权六久阁网出售该小程序,大家注意不要上当



版权声明:本文为原创文章,未经允许不得转载。https://doc.tengcee.com/dedecms/apis/84.html

服务热线

15137100750

我知道你不会打


但是我还是要写


你懂得!

微信二维码

QQ群二维码