织梦百度小程序增加自定义表单功能-自定义表单diyform
接口名称:小程序自定义表单
接口标识:diyform
接口url:https://你的网站/api/index.php?action=diyform&type=post
更多织梦百度小程序API请移步《织梦百度小程序及微信小程序万能API接口插件》

接口参数:
(1)diyid: 自定义表单id 必填
(2)type: 操作类型 post:默认,提交表单、list:读取列表、view:阅读提交内容
type不同所需参数也不同
1、当type=post时候,提交表单
此时除了必须的aid、type之外,其他的参数需要和你的后台参数类型相同
2、当type=list时,获取对应表单的内容列表
(1)diyid:1 表单id,必填(默认只调用审核过的内容)
(2)num:10 如果num存在则调用指定数量评论,否则按照分页调用;
(3)page:1 当前页面,默认为1;
(4)pagesize:10 自定义页面大小,默认后台设置的页面大小;
3、当type=view时候
(1)diyid:1 表单id,必填(默认只调用审核过的内容)
(2)id:10 内容id,必填
小程序参考代码:
<form bindsubmit="formSubmitHandle"> 
        <view class='form_input'> 
              <input placeholder="请填写您的姓名" value='{{name}}' name='name' /> 
        </view> 
        <view class='form_input'> 
              <input type='digit' placeholder="请填写电话" name='phone' value='{{phone}}' auto-focus/> 
        </view> 
        <view class='form_input'> 
              <input type='text' placeholder="请填写QQ或邮箱" name='qq' /> 
        </view> 
        <view class='form_input'> 
          <checkbox-group class="checkbox-group" name='xuqiu'> 
              <checkbox value="网站建设" checked/>网站建设</checkbox> 
              <checkbox value="域名空间" />域名空间</checkbox> 
              <view class="c"></view> 
              <checkbox value="网站改版" />网站改版</checkbox> 
               <checkbox value="小程序开发" />小程序开发</checkbox> 
          </checkbox-group> 
        </view> 
        <input type='text' name='diyid' value="1" hidden='{{true}}'/> 
        <view class='form_input'> 
              <textarea class='form_textarea' name="content" placeholder="留言内容" /> 
        </view> 
        <view class="c"></view> 
        <view class="btn-area"> 
           <button form-type="submit">提交留言</button> 
        </view> 
    </form>小程序js代码:
formSubmitHandle: function (e) { 
        console.log(e) 
        var that = this 
        /*复选框整合*/ 
        var xuqiu = ''; 
        for (var i in e.detail.value.xuqiu) { 
            xuqiu += e.detail.value.xuqiu[i] + ','; 
        } 
        var that = this; 
        if (e.detail.value.name == '') { 
            e.detail.value.name = '匿名' 
        } 
        if (e.detail.value.phone.length == 0) { 
            swan.showModal({ 
                content: '电话不能为空', 
                confirmText: '确定', 
                cancelText: '取消' 
            }); 
        } else if (e.detail.value.content.length == 0) { 
            swan.showModal({ 
                content: '内容不能为空', 
                confirmText: '确定', 
                cancelText: '取消' 
            }); 
        } else { 
            swan.request({ 
                url: app.globalData.api + "action=diyform", 
                data: { 
                    diyid: e.detail.value.diyid,//必填 
                    name: '【百度】' + e.detail.value.name,//区分正常留言,可以去掉 
                    phone: e.detail.value.phone, 
                    qq: e.detail.value.qq, 
                    xuqiu: xuqiu, 
                    content: e.detail.value.content, 
                    type: 'post', 
                    aid: app.globalData.aid//必填 
                }, 
                method: 'POST', 
                header: { 
                    'content-type': 'application/x-www-form-urlencoded', 
                    'x-appsecret': app.globalData.appsecret 
                }, 
                success: function (res) { 
                    console.log(res) 
                    if (res.data.status == 'ok') { 
                        swan.showToast({ 
                            title: '留言成功!!', 
                            icon: 'success', 
                            duration: 1500, 
                            success: function () { 
                                setTimeout(function () { 
                                    swan.navigateBack(); 
                                }, 2000) 
                            } 
                        }) 
                    } else { 
                        swan.showToast({ 
                            title: '留言失败,请重新提交!!', 
                            icon: 'warn', 
                            duration: 1500 
                        }) 
                    } 
                    setTimeout(function () { 
                        swan.hideToast() 
                    }, 2000) 
                } 
            }) 
        } 
    },小程序获取表单内容列表代码:
get_msglist(diyid) { 
        swan.request({ 
            url: app.globalData.api + "action=diyform", 
            data: { 
                diyid: diyid,//必填 
                type: 'list', 
                aid: app.globalData.aid//必填 
            }, 
            method: 'POST', 
            header: { 
                'content-type': 'application/x-www-form-urlencoded', 
                'x-appsecret': app.globalData.appsecret 
            }, 
            success: function (res) { 
                console.log(res) 
            } 
        }) 
    },注意事项
(1)由于dedecms自带的安全检测的防注入代码,会造成表单无法提交提示:Safe Alert: Request Error step 2!,此时需要对dedecms源码做个修改即可
打开include下的dedesql.class.php找到构造函数
function __construct($pconnect=false,$nconnect=true) 
{ 
$this->isClose = false; 
$this->safeCheck = true;//改成FALSE即可 
if($nconnect) 
{ 
$this->Init($pconnect); 
} 
}织梦二次开发QQ群
本站客服QQ号:862782808(点击左边QQ号交流),群号(383578617)  如果您有任何织梦问题,请把问题发到群里,阁主将为您写解决教程!
  如果您有任何织梦问题,请把问题发到群里,阁主将为您写解决教程!
转载请注明: 织梦模板 » 织梦百度小程序增加自定义表单功能

 
  
  
		









 
        


























