• Tp3.2提交表单与操作表单


    笔记笔记

    先去建个表————

    然后把我输入的东西 存到表里:

    <input type="submit" id="tijiao" value="提交" style="background-color:#fa6374; color:#FFF; cursor:pointer; border:0px; margin-left:63px;">

    这里用的提交按钮,以form的方式

    form是这么写的:

     <form action="{:U('validate')}" method="post" name="myform">

    然后我们去validate方法里去做处理:

    <?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 ThinkVerify();
                $yzmyz = $verify->check($yzm);
    
                if(!$yzmyz){
    
                    $this->error('验证码错误');
    
                }
                else{
                    $validate = M("liuyan3");
                    $validate->add($date);
                    $this->success('添加成功');
    
                }
            }
    //    }

    我注释的是验证;

    这样一来  我输入的东西就存进了数据表里面,

    我还需要在后台把他们遍历出来,我来控制它;

    便利很简单:

    <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>&nbsp;&nbsp;
                    <a>
                        <i></i> 删除</a>
                </td>
            </tr>
    
        </article:list>

    然后做个修改吧:

    修改连接到该控制器的xg方法,还顺便传了一下id;

    看一下ajax处理,ajax简单

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

    然后后台处理:

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

    璇哥的笔记@@

  • 相关阅读:
    leetcode5 Longest Palindromic Substring
    leetcode17 Letter Combinations of a Phone Number
    leetcode13 Roman to Integer
    leetcode14 Longest Common Prefix
    leetcode20 Valid Parentheses
    leetcode392 Is Subsequence
    leetcode121 Best Time to Buy and Sell Stock
    leetcode198 House Robber
    leetcode746 Min Cost Climbing Stairs
    tomcat下使用druid配置jnid数据源
  • 原文地址:https://www.cnblogs.com/xuan584521/p/7279669.html
Copyright © 2020-2023  润新知