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

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

黄舟
Release: 2023-03-14 21:20:02
Original
5685 people have browsed it

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;">
Copy after login

The submit button used here is in form

The form is written like this:


 <form action="{:U(&#39;validate&#39;)}" method="post" name="myform">
Copy after login

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;);

            }
        }//    }
Copy after login

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>
Copy after login

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>
Copy after login

Then background processing:


<?public function xg()
    {        
    $id=I(&#39;get.code&#39;);        
    $this->assign("arr2",$id);        
    $this->display(&#39;tg:public/xg&#39;);
    }    
    public function deal()
    {        
    $id=I(&#39;post.id&#39;);        
    $data[&#39;name&#39;]=I(&#39;post.name&#39;);        
    $data[&#39;tel&#39;]=I(&#39;post.tel&#39;);        
    $data[&#39;youxiang&#39;]=I(&#39;post.email&#39;);        
    $data[&#39;address&#39;]=I(&#39;post.address&#39;);        
    $data[&#39;content&#39;]=I(&#39;post.content&#39;);        
    $db=M(&#39;liuyan3&#39;);        
    $r=$db->where("id=&#39;{$id}&#39;")->save($data);
dump($r);

    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template