主要内容:实现微信小程序与PHP后台之间的数据传递

本文通过from表单提交到后台存入数据库来展现

需要注意的有:
勾选

代码如下:
demo1.wxml

<!--pages/demo1/demo1.wxml-->
<form bindsubmit='formSubmit'  bindreset='formReset'><view class="container"><view class="login-from"><!--姓名--><view class="inputView"><label class="loginLab">姓名</label><input class="inputText" name="name" placeholder="请输入姓名" /></view><view class="line"></view><!--手机号--><view class="inputView"><label class="loginLab">手机号</label><input class="inputText" name="mobile"  placeholder="请输入手机号" /></view><!--登录按钮--><view class="loginBtnView"><button class="loginBtn" catchtap="submit" type="primary" form-type='submit'>提交</button><button class="loginBtn" type="primary" form-type='reset'>重置</button></view></view></view>
</form>

demo1.wxss

/* pages/demo1/demo1.wxss */
page{height: 100%;
}.container {height: 70%;display: flex;flex-direction: column;padding: 0;box-sizing: border-box;background-color: #f2f2f2
} /*表单内容*/
.login-from {margin-top: 20px;flex: auto;height:100%;
}.inputView {background-color: #fff;line-height: 44px;
}
/*输入框*/
.nameImage, .keyImage {margin-left: 22px;width: 14px;height: 14px
}.loginLab {margin: 15px 15px 15px 10px;color: #545454;font-size: 14px
}
.inputText {flex: block;float: right;text-align: right;margin-right: 22px;margin-top: 11px;color: #cccccc;font-size: 14px
}/*按钮*/
.loginBtnView {width: 750rpx;height: 750rpx;background-color: #f2f2f2;margin-top: 0px;margin-bottom: 0px;padding-bottom: 0px;
}.loginBtn {width: 350rpx;margin-top: 15rpx;margin-left: 17rpx;float: left;
}

demo1.js

//var url = 'http://wxtest.com/index.php/index'//tp5
var url = 'http://localhost/wxphp/form.php'//源生
Page({data: {},formSubmit: function (e) {var that = thiswx.request({url: url,data: {'name': e.detail.value.name,'mobile': e.detail.value.mobile,},method: 'GET',header: {'content-type': 'application/json'},success: function (res){console.log(1111);console.log(res.data.status);if (res.data.status == 1) {wx.showToast({title: res.data.info,duration: 2000});}else{wx.showToast({title: '提交失败',duration: 2000});}},})}
})

PHP后台代码分两种方式接收:源生和TP5.1框架

源生:
from.php

<?php
//设置编码utf—8
header('Content-type:text/html;charset=utf-8');
//接收数据
$name = $_GET['name'];
$mobile = $_GET['mobile'];
//连接数据库
$con = new mysqli("localhost","root","root","wxphp");
//定义sql语句
$sql = "INSERT INTO user(name,mobile) values('$name','$mobile ');";
//发送sql语句
$res = mysqli_query($con,$sql);
if($res){$arr['status'] = 1;$arr['info'] = '提交成功';
}else{$arr['status'] = 0;$arr['info'] = '提交失败';
}
echo json_encode($arr);
die;

TP5.1:

<?php
namespace app\index\controller;
use think\Db;class Index
{public function index(){//接收数据$data = input('post.');//将数据存入数据库$res = Db::name('user')->insert($data);//将结果反馈给前台if($res){$arr['status'] = 1;$arr['info'] = '提交成功';}else{$arr['status'] = 0;$arr['info'] = '提交失败';}echo json_encode($arr);die;
}

本案例只是简单地将数据从微信小程序前台提交给PHP后台,然后后台将数据存入数据库,没有过多地验证规则

效果图如下:


微信小程序之from表单提交数据到PHP后台相关推荐

  1. 微信小程序+SpringMVC图文表单提交(包括前后端代码)

    文章目录 前言 一.基本功能说明 二.小程序前端 三.SpringMVC后端 总结 前言 本项目使用微信小程序+SpringMVC搭建.这里展示的是其中表单提交的部分(图片和文字).本文包括前后端关键 ...

  2. 微信小程序中form 表单提交和取值实例详解

    2019独角兽企业重金招聘Python工程师标准>>> 我们知道,如果我们直接给 input 添加 bindinput,比如:<input bindinput="on ...

  3. 小程序 | 微信小程序from报名表单提交至数据库(含js提交函数)

    效果图 index.wxml <form bindsubmit="formSubmit" bindreset="formReset"><!-- ...

  4. 微信小程序表单提交php存储,微信小程序实现form表单本地储存数据

    本文实例为大家分享了微信小程序实现form表单本地储存数据的具体代码,供大家参考,具体内容如下 效果图: 主要利用小程序的getStorage来实现异步本地储存. 小程序目录结构如下: 新建项目前,为 ...

  5. 微信小程序的动态表单,实现房屋租赁的多租客录入

    0 前言 本文将介绍如何使用微信小程序编写动态表单,最终实现房屋租赁系统中多租客录入的业务. 在阅读本文前,您需要对微信小程序的开发有一个初步的了解,以便更容易的学会开发动态表单. 作者主页:Desi ...

  6. 微信小程序开发之表单验证(WxValidate使用)

    微信小程序的开发框架个人感觉大体上跟VUE是差不多的,但是他的表单组件没有自带的验证功能,因此开发小程序的表单验证时候一般有两种方法,一是自己裸写验证规则,但是需要比较扎实的正则表达式基础,一种是利用 ...

  7. 微信小程序之获取表单数据

    前言:微信小程序中很多地方运用到了表单,很多时候我们需要把表单中的内容提取出来返回给后台,这里我随便写了一点 注意点: 1.所有的input  textarea button全部包含在form表单元素 ...

  8. 微信小程序开发——form表单

    WeChat小程序交流(QQ群:769977169) 效果图 代码示例 1.xxx.wxml <form bindsubmit='submitClick' bindreset='resetCli ...

  9. 微信小程序之自定义表单组件(radio)

    背景: 最近在做项目的时候遇到一个问题,那就是微信的官方表单组件的可扩展性不强,无法达到设计稿所要求的效果,所以想到了用自定义组件的方法自定义一个表单组件. (自定义组件其实往往用在需要复用的地方,比 ...

最新文章

  1. matlab支持的文件类型,MATLAB可以读取的数据文件类型有()
  2. Python: sklearn库——数据预处理
  3. pytorch 常见报错
  4. 汇编语言位向量(位映射)
  5. pythonjson数据提取_python爬虫学习笔记(十)-数据提取之JsonPath的使用
  6. linux swftools java_linux下安装swftools工具
  7. 清理神器CleanMyMac X 空间透镜——可视化您的磁盘空间
  8. python如何对文件进行批量命名-利用Python对文件批量重命名
  9. Android Gallery3D源码分析
  10. 史上最全的并发编程学习目录
  11. etherlime-3-Etherlime Library API-Deployed Contract Wrapper
  12. JSONSerializer把类转换成JSON字符串
  13. Ten graph questions of about 2000 difficulty of Codeforces Round 1
  14. addEventListener和attachEvent
  15. Dotnet WebAPI 项目启动提示 500.30 - ANCM In-Process Start Failure
  16. 通俗易懂区块链系列——双重支付/双花支付
  17. 斜线“\”与反斜线“/”应用场景的整理
  18. 计算机切屏的三种快捷键,小技巧:笔记本切换屏幕快捷键_计算机的基本知识_IT /计算机_信息...
  19. 微信小程序解密用户信息--java解密
  20. DTV 学习(一) 基本概念、分类

热门文章

  1. 从2016年的11月1日开始
  2. 新版TCGA的甲基化数据分析
  3. new/delete
  4. Elasticsearch01
  5. 组合学笔记(一)偏序集概念与应用
  6. Python selenium PIL 全网页滚动截屏 headless全网页截屏
  7. NYOJ_236_心急的C小加
  8. 前端 | (二)各种各样的常用标签 | 尚硅谷前端html+css零基础教程2023最新
  9. 321_MediaType Media Type 是什么
  10. 【无刷直流电机--闭环控制】【Stm32G070】【例程是hal库】增加按键长按使系统初始化