11)PHP,checkbox的post提交方式處理

來源:互聯網
上載者:User

標籤:echo   ref   put   type   obb   rds   等等   網頁   XML   

    就是一個表單中會有input的checkbox形式,那麼怎麼處理,就有了問題,一般採用二維數組來處理

代碼展示:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> 3 <head> 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5     <title>網頁標題</title> 6     <meta name="keywords" content="關鍵字列表" /> 7     <meta name="description" content="網頁描述" /> 8     <link rel="stylesheet" type="text/css" href="" /> 9     <style type="text/css"></style>10     <script type="text/javascript"></script>11 </head>12 <body>13     <form  action="c.php"  method="get" >14         項目1: <input type="text"   name="uName"   />15         項目2: <input type="password"   name="uPswd"   />16         項目3: <input type="text"   name="age"   />17         <br />18         愛好:19             <input type="checkbox" name="hobby[]" value="足球" />足球20         <input type="checkbox" name="hobby[]" value="籃球" />籃球21         <input type="checkbox" name="hobby[]" value="中國足球" />中國足球22         <br />23         <input type="submit"  value="提交"  />24     </form>25     <hr />26     <a  href="4get_2.php?uName=test1&uPswd=123"  > 文字。。。</a>27 </body>28 </html>

然後,我的那個php代碼處理:

或者這麼寫:
echo
$_GET[‘hobby‘][‘0‘];

1 var_dump($_GET[‘hobby‘][‘0‘]) ;

注意:這個看你選擇了幾個,要是  你選擇了兩個,那麼是      $_GET[‘hobby‘][‘0‘]   ~~~~~··$_GET[‘hobby‘][‘1‘]

          但是  ,你要是沒選

                  ,

                  就沒有$_GET[‘hobby‘][‘0‘]等等

 

 

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn"> 3 <head> 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5     <title>網頁標題</title> 6     <meta name="keywords" content="關鍵字列表" /> 7     <meta name="description" content="網頁描述" /> 8     <link rel="stylesheet" type="text/css" href="" /> 9     <style type="text/css"></style>10     <script type="text/javascript"></script>11 </head>12 <body>13 <form  action="c.php"  method="get" >14   15     單選框:<br>16     男性:17     <input type="radio" checked="checked" name="Sex" value="male" />18     <br />19     女性:20     <input type="radio" name="Sex" value="female" />21 <br>
或者上面的這麼處理:
單選框:<br>
男性:
<input type="radio" checked="checked" name="Sex【】" value="male" />
<br />
女性:
<input type="radio" name="Sex【】" value="female" />

22 愛好:23 <input type="checkbox" name="hobby[]" value="足球" />足球24 <input type="checkbox" name="hobby[]" value="籃球" />籃球25 <input type="checkbox" name="hobby[]" value="中國足球" />中國足球26 <br />27 28 </body>29 </html>

處理代碼:

 

 

var_dump($_GET[‘Sex‘]) ;
這個結果是一個string

第二種處理:

 

var_dump($_GET[‘Sex‘][‘0‘]) ;
這個結果是一個string

 

11)PHP,checkbox的post提交方式處理

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.