Detailed explanation of examples of submitting forms and operating forms in ThinkPhp3.2
First create a table————
Then What I entered is saved in the table:
<input type="submit" id="tijiao" value="提交" style="background-color:#fa6374; color:#FFF; cursor:pointer; border:0px; margin-left:63px;">
The submit button used here is in form
The form is written like this:
<form action="{:U('validate')}" method="post" name="myform">
Then we go to the validate method to do the processing:
<?php public function validate(){ $date['name'] = I('post.lc_name'); $date['tel'] = I('post.lc_tel'); $date['youxiang'] = I('post.lc_email'); $date['address'] = I('post.lc_address'); $date['content'] = I('post.lc_content'); $yzm = I('post.code');// $fkyz = D("Liuyan"); /**/ // // if (!$fkyz->create()){ // // 如果创建失败 表示验证没有通过 输出错误提示信息 // exit($fkyz->getError()); // // }else{ // 验证通过 可以进行其他数据操作 $verify = new \Think\Verify(); $yzmyz = $verify->check($yzm); if(!$yzmyz){ $this->error('验证码错误'); } else{ $validate = M("liuyan3"); $validate->add($date); $this->success('添加成功'); } }// }
What I commented is verification;
In this way, the things I input are stored in the data table.
I also need to traverse them in the background, and I will control it;
The convenience is very simple:
<article:list type="liuyan3" limit="" order="id asc" where=""> <tr> <td>{$v.id}</td> <td>{$v.name}</td> <td>{$v.tel}</td> <td>{$v.youxiang}</td> <td>{$v.address}</td> <td>{$v.content}</td> <td> <a href="__CONTROLLER__/xg?code={$v.id}"> <i></i> 编辑</a> <a> <i></i> 删除</a> </td> </tr> </article:list>
Then make a modification:
Modify the xg method connected to the controller, and pass the id by the way;
Look at ajax processing, ajax is simple
<script> var config = { '.chosen-select': {}, } for (var selector in config) { $(selector).chosen(config[selector]); } deal(); function deal() { $("#btn_s").click(function(){ var id=$("#ids").val(); var name=$("#laiyuan").val(); var tel=$("#laiyuan2").val(); var email=$("#views").val(); var address=$("#laiyuan_url").val(); var content=$("#liuyan").val(); alert(content); alert(id); alert(name); alert(email); alert(address); $.ajax({ url:"__CONTROLLER__/deal", data:{id:id,name:name,tel:tel,email:email,address:address,content:content}, dataType:"TEXT", type:"POST", success: function(r) { window.location.href="__CONTROLLER__/index"; } }) }) }</script> </body>
Then background processing:
<?public function xg() { $id=I('get.code'); $this->assign("arr2",$id); $this->display('tg:public/xg'); } public function deal() { $id=I('post.id'); $data['name']=I('post.name'); $data['tel']=I('post.tel'); $data['youxiang']=I('post.email'); $data['address']=I('post.address'); $data['content']=I('post.content'); $db=M('liuyan3'); $r=$db->where("id='{$id}'")->save($data); dump($r); }
The above is the detailed content of Detailed examples of submission forms and operation forms in ThinkPhp3.2. For more information, please follow other related articles on the PHP Chinese website!