了解最新公司动态及行业资讯
接口名称:小程序自定义表单
接口标识:form
接口url:https://你的网站/api.php/index/form
接口参数:
| 字段名称 | 字段说明 | 类型 | 必填 | 备注 |
|---|---|---|---|---|
| fid | 表单id | num | 必填 | |
| type | 操作类型 | string | 可不填 | 可选参数:post/提交表单、list/读取列表 |
| num | 数量 | num | 可不填 | 调用数量,默认10,为空则按照分页调用 |
type不同所需参数也不同
1、当type=post时候,提交表单
此时除了必须的type之外,其他的参数需要和你的后台参数类型相同
2、当type=list时,获取对应表单的内容列表
| 字段名称 | 字段说明 | 类型 | 必填 | 备注 |
|---|---|---|---|---|
| fid | 表单id | num | 必填 | |
| type | 操作类型 | string | 必填 | 可选参数:post/提交表单、list/读取列表、view/阅读;默认:post |
| num | 数量 | num | 可不填 | 调用数量,默认10,为空则按照分页调用 |
| pagesize | 自定义分页大小 | num | 可不填 | 默认后台设置的页面大小 |
| order | 排序 | string | 可不填 | 默认:"id desc";该接口暂无开放 |
3、当type=view时候 暂未开启
| 字段名称 | 字段说明 | 类型 | 必填 | 备注 |
|---|---|---|---|---|
| fd | 表单id | num | 必填 | |
| type | 操作类型 | string | 必填 | 可选参数:post/提交表单、list/读取列表、view/阅读;默认:post |
| id | 内容ID | num | 必填 | (若该内容为未审核内容则直接返回错误信息) |
小程序参考代码:
code腾石建站
<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='fid' 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代码:
code腾石建站
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 + "form",
data: {
fid: e.detail.value.fid,//必填
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)
}
})
}
},
小程序获取表单内容列表代码:
code腾石建站
get_msglist(diyid) {
swan.request({
url: app.globalData.api + "form",
data: {
fid: fid,//必填
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)
}
})
},
上一篇:用户授权登录member
下一篇:公司信息company