Home  >  Article  >  Backend Development  >  Detailed examples of submission forms and operation forms in ThinkPhp3.2

Detailed examples of submission forms and operation forms in ThinkPhp3.2

黄舟
黄舟Original
2017-08-11 09:31:555635browse

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(&#39;validate&#39;)}" method="post" name="myform">

Then we go to the validate method to do the processing:


<?php    
public function validate(){        
$date[&#39;name&#39;] = I(&#39;post.lc_name&#39;);        
$date[&#39;tel&#39;] = I(&#39;post.lc_tel&#39;);        
$date[&#39;youxiang&#39;] = I(&#39;post.lc_email&#39;);        
$date[&#39;address&#39;] = I(&#39;post.lc_address&#39;);        
$date[&#39;content&#39;] = I(&#39;post.lc_content&#39;);        
$yzm = I(&#39;post.code&#39;);//        
$fkyz = D("Liuyan");
/**/
//
//        if (!$fkyz->create()){
//            // 如果创建失败 表示验证没有通过 输出错误提示信息
//            exit($fkyz->getError());
//
//        }else{

            // 验证通过 可以进行其他数据操作
            $verify = new \Think\Verify();            
            $yzmyz = $verify->check($yzm);            
            if(!$yzmyz){                
            $this->error(&#39;验证码错误&#39;);

            }            
            else{                
            $validate = M("liuyan3");                
            $validate->add($date);                
            $this->success(&#39;添加成功&#39;);

            }
        }//    }

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 = {        
&#39;.chosen-select&#39;: {},
    }    
    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:


9c383d93476279d3867fb17411c25538assign("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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn