![](/uploads/image/0063.jpg)
注册学⽣信息⾸先我们要检测学⽣信息不能为空,然后检测前台传过来的学号是否已经注册,若已注册,返回学号存在;反之添加进数据库student表: public function index($no,$name,$sex,$age){
//⾮空
if(empty($no)||empty($name)){
return $this->ajaxReturn(array('error'=>true,'msg'=>'学号或姓名不能为空'));
}
$data['no'] = $no;
$data['name'] = $name;
$data['sex'] = $sex;
$data['age'] = $age;
$stu = M('student');
//不可重复
if($stu->where("no = '{$no}'")->find()){
return $this->ajaxReturn(array('error'=>true,'msg'=>'学号已存在'));
}else{
$id=$stu->add($data);
}
if($id){
$this->ajaxReturn(array('error'=>false,'id'=>$id));
}else{
$this->ajaxReturn(array('error'=>true,'msg'=>'添加失败'));
}
}
页⾯代码:
<form bindsubmit='submit'>
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">学号</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="no" placeholder="请输⼊学号" />
</view>
</view>
三亚哪个区最繁华<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">
<view class="weui-label">姓名</view>
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="name" placeholder="请输⼊姓名" />
</view>
</view>
<view class="weui-cell weui-cell_switch">
<view class="weui-cell__bd">性别</view>
<input class="weui-input" name="sex" placeholder="请输⼊性别" value='{{sex}}'/> <view class="weui-cell__ft">
<switch checked bindchange='switchChange' />
</view>
</view>
<view class="weui-cell weui-cell_input">
<view class="weui-cell__hd">云南旅游地图景点地图全图
<view class="weui-label">年龄</view>莆田旅行社跟团游
</view>
<view class="weui-cell__bd">
<input class="weui-input" name="age" placeholder="请输⼊年龄"/>
</view>
</view>
<view class="weui-btn-area">
<button class="weui-btn" type="primary" form-type='submit'>注册</button>
<button class="weui-btn" type="warn" form-type='reset'>重置</button>
<button class="weui-btn" bindtap='backbefore' >返回上⼀级</button>
</view>
香港维多利亚港房价
</form>
页⾯效果:
根据后台的代码我们可以知道我们需要传4个参数:no,name,sex,age post⽅式提交;
给form表单绑定⼀个bindsubmit,当我们点击注册时,会把值存在e⾥边
submit: function (e) {
// console.log(e);
}
我们使⽤wx.resquest,将所需的参数传给后台
这样就连接起来了
js代码:
data: {
sex: '男',
},
backbefore:function(){
wx.navigateBack({
delta:1
})
},
switchChange: function (e) {
// console.log(e);
if (e.detail.value) {
this.setData({ sex: '男' })
} else {
this.setData({ sex: '⼥' })
}
},
submit: function (e) {
// console.log(e);
url:'xxxxxxxxxxxxx',//这⾥调⽤⾃⼰的接⼝
method: 'POST',
data: {
no: e.,
美国签证中心查询
name: e.detail.value.name,
sex: e.detail.value.sex,
age: e.detail.value.age
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值 },
success: (res) => {
// console.log(res.data);
if () {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000,
})
} else {
wx.setStorage({
key: "id",
data: res.data.id
});
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
})
}
}
})
},