HTML提交表單後php的獲取方法[超簡單、無涉及資料庫]
阿新 • • 發佈:2018-12-20
記錄一下,怕忘了
表單
提交的內容如圖
<form class="form" action="login.php" method="post"> <div> <label class="first" for="tel"><span class="star">*</span>請輸入手機號碼:</label> <input onkeyup="if(! /^\d+$/.test(this.value)){alert('只能0~9');this.value='';}" onfocus="setbackground(this.id)" onblur="getbackground(this.id)" id="tel" class="tel" name="tel" placeholder="請輸入手機號碼" type="tel" /> <button class="button" type="button">免費獲取證碼</button> <p class="contex">完成註冊後手機為你的微博登入號</p> </div> <div> <label class="first" for="pass"><span class="star">*</span>建立密碼:</label> <input onfocus="setbackground(this.id)" onblur="getbackground(this.id)" id="pass" class="pass" placeholder="請輸入密碼" type="password" name="pass"/> <p class="button textarea">為了你的賬戶安全請輸入不同其他賬戶的密碼</p> </div> <div> <label class="first" for="name1"><span class="star">*</span>暱稱:</label> <input onfocus="setbackground(this.id)" onblur="getbackground(this.id)" id="name1" class="name" placeholder="請輸入暱稱" type="text" name="name"/> <p class="common"></p> </div> <div> <label class="first" for="boy"><span class="star">*</span>性別:</label> <input type="radio" name="sex" value="boy" id="boy" /><label for="boy">男</label> <input type="radio" name="sex" value="gril" id="gril"/><label for="gril">女</label> <p class="common"></p> </div> <div> <label class="first" for="select" ><span class="star">*</span>所在地:</label> <select id="select" name="select"> <option>北京市</option> <option>上海市</option> <option>廣州市</option> <option>深圳市</option> </select> <select> <option>海淀區</option> <option>東城區</option> <option>海珠區</option> <option>福田區</option> <option>越秀區</option> <option>黃浦區</option> </select> <p class="common"></p> </div> <div> <label class="first" for="boy"><span class="star">*</span>手機驗證碼:</label> <input onfocus="setbackground(this.id)" onblur="getbackground(this.id)" type="text" name="code" id="code" /> <p class="common"></p> </div> <div> <input type="submit" id="btn" class="btn"> </div> </form>
PHP獲取
<?php $cityArr = array("廣州市"=>"020", //用一個數組來儲存城市對應的區號,實際中應該從資料庫獲取 "深圳市"=>"0755", "北京市"=>"010", "上海市"=>"021" ); ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>php表單提交</title> <style> body{ margin: 0;padding: 0; background-image: url(img/bk.png); background-repeat: repeat; } .main{ margin-right:auto ; margin-left: auto; background-image: url(img/form1.png); background-repeat: no-repeat; width: 552px; height: 552px; } .form{ width: 510px; height: 410px; padding-top: 105px; position: relative; } label{ display: inline-block; width: 160px; padding-left:20px ; text-align: right; } </style> </head> <body> <div class="main"> <div class="form"> <p><label>你的手機號:</label> <?php echo $_POST["tel"] ?>//獲取提交的手機號,這裡面的tel和input中的name相對應,下面都一樣 </p> <p><label>建立的密碼:</label> <?php echo $_POST["pass"] ?> </p> <p><label>暱稱:</label> <?php echo $_POST["name"] ?> </p> <p><label>性別:</label> <?php echo $_POST["sex"] ?> </p> <p><label>所在地:</label> <?php echo $_POST["select"] ?> </p> <p><label>所在區號:</label> <?php echo $cityArr[$_POST["select"]] ?>//這裡的select也是一樣,要個下拉框弄個name屬性 </p> <p><label>手機驗證碼:</label> <?php echo $_POST["code"] ?> </p> </div> </div> </body> </html>
效果