tp3.2 ajax 表單提交

來源:互聯網
上載者:User

標籤:comment   post   create   conf   javascrip   name   tle   isp   表單   

前台:

  1 <form action="javascript:;" method="post" class="form_div" id="tj">  2   3                     <ul class="feed_ul clearfix">  4                         <li>  5                             <div class="div_biao"><i class=" icon-user"></i> 姓名<i>*</i></div>  6                             <input style="background: #ededed;" class="form-control" type="text" name="lc_name" placeholder=""   id="name"/>  7   8                         </li>  9                         <li> 10                             <div class="div_biao"><i class=" icon-home"></i> 公司<i>*</i></div> 11                             <input style="background: #ededed;" class="form-control" type="text" name="lc_company" placeholder=""  id="phone"/> 12  13  14                         </li> 15                         <li> 16                             <div class="div_biao"><i class=" icon-volume-down"></i> 電話<i>*</i></div> 17                             <input style="background: #ededed;" class="form-control" type="text" name="lc_tel" placeholder=""  id="add"/> 18  19                         </li> 20                         <li> 21                             <div class="div_biao"><i class=" icon-comment"></i> 郵 箱<i>*</i></div> 22                             <input style="background: #ededed;" class="form-control" type="text" name="lc_email" placeholder=""   id="email"/> 23  24                         </li> 25  26                         <br /> 27  28                         <li> 29  30                             <input type="text" name="code" class="form-control pword" id="code" placeholder="驗證碼" oncontextmenu="return false" onpaste="return false"  style="background: #ededed;" /> 31                             <br /> 32                             <img onClick="this.src=this.src+‘?‘+Math.random();" title="看不清楚?點擊重新整理驗證碼?" class="verifyimg reloadverify" alt="點擊切換" src="{:U(‘verify‘)}" height="80%";  /> 33  34                         </li> 35  36                         <br/> 37  38             <li style="text-align: center"> 39                 <input  type="button" class="btn btn-primary"  onClick="formsubmit()" value="提交"> </input> 40             </li> 41  42  43  44             <script type="text/javascript"> 45                 function formsubmit() 46                 { 47  48                     var name=$("input[name=lc_name]").val(); 49                     var tel=$("input[name=lc_tel]").val(); 50                     var company=$("input[name=lc_company]").val(); 51                     var email=$("input[name=lc_email]").val(); 52                     var code=$("input[name=code]").val(); 53  54  55  56                     if(!name) 57                     { 58                         alert(‘姓名不可為空!‘); 59                         return false; 60                     } 61                     if(!company) 62                     { 63                         alert(‘公司地址不可以為空白!‘); 64                         return false; 65                     } 66  67                     //手機號 68                     if(!/^1\d{10}$/.test(tel)){ 69                         alert(‘請輸入正確手機號碼!‘); 70                         return false; 71                     } 72  73                     if(!/^(\w-*\.*)[email protected](\w-?)+(\.\w{2,})+$/.test(email) ) 74                     { 75                         alert(‘請輸入正確郵箱!‘); 76                         return false; 77                     } 78                     if(!code) 79                     { 80                         alert(‘驗證碼不可以為空白!‘); 81                         return false; 82                     } 83  84  85                     //$("#tj").attr("action","zxbm").submit(); 86  87  88                     $.ajax({ 89                         async:false, 90                         url:"__ROOT__/Home/Index/zxbm", 91                         data:{lc_name:name,lc_tel:tel,lc_company:company,lc_email:email,code:code}, 92                         type:"POST", 93                         datatype:"TEXT", 94                         success:function(data){ 95  96                             if(data=="線上報名成功!") 97                             { 98                                 alert(data); 99                                 window.location.href="__ROOT__/Home/Index/index";100                             }101                             else102                             {103                                 alert(data);104                             }105 106 107                         }108                     });109 110 111                 }112 113 114 115             </script>116 117 118 119 120         </ul>121 122 </form>

後台:

 1     public function zxbm() 2     { 3  4         if(IS_POST) 5         { 6  7  8             $verify = new \Think\Verify(); 9             $yzjg = $verify->check($_POST[‘code‘]);10             if($yzjg)11             {12                 $zxbm = D("zxbm"); // 執行個體化User對象13                 $zxbm->create(); // 產生資料對象14                 $res = $zxbm->add(); // 新增使用者資料15 16                 if($res)17                 {18                     $data =‘線上報名成功!‘;19                     $this->ajaxReturn($data);20                 }21                 else22                 {23                     $data =‘線上報名失敗!‘;24                     $this->ajaxReturn($data);25                 }26             }27             else28             {29                 $data =‘輸入的驗證碼有誤!‘;30                 $this->ajaxReturn($data);31             }32 33 34 35         }36 37        38         $this->display();39 40     }41 42     public function verify(){43         $config =    array(44             ‘fontSize‘    =>    45,    // 驗證碼字型大小45             ‘length‘      =>    4,     // 驗證碼位元46         );47         $Verify = new \Think\Verify($config);48         $Verify->entry();49 50 51     }

 

tp3.2 ajax 表單提交

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.