PHP表單元素

2018-02-22 16:40 更新

PHP教程 - PHP表單元素

表單元素列表

下表列出了表單中的HTML元素。

元件 描述
input type =“checkbox" 允許用戶選擇多個選項的復選框。
input type =“file" 文本框以及打開文件選擇對話框的按鈕。
input type =“hidden" 隱藏表單元素。
輸入類型=“密碼" 密碼文本框。
input type =“radio" 單選按鈕。
輸入類型=“復位" 用于清除表單的按鈕。
input type =“submit" 提交表單的按鈕。
input type =“text" 文本框。
option SELECT元素中的選項。
select 列表框; 也可以是一個下拉列表框。
textarea 多行文本框。

密碼元素通過使用* s在客戶端隱藏密碼。密碼以無加密的純文本發(fā)送。



例子

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
  <body> 
    <form action="index.php" method="get"> 
        <label for="textField">A text input field</label> 
        <input type="text" name="textField" id="textField" value="" /> 
        <label for="passwordField">A password field</label> 
        <input type="password" name="passwordField" id="passwordField" value="" /> 
        <label for="checkboxField">A checkbox field</label> 
        <input type="checkbox" name="checkboxField" id="checkboxField" value="yes" /> 
        <label for="radioButtonField1">A radio button field</label> 
        <input type="radio" name="radioButtonField" id="radioButtonField1" value="radio1" /> 
        <label for="radioButtonField2">Another radio button</label> 
        <input type="radio" name="radioButtonField" id="radioButtonField2" value="radio2" /> 
        <label for="submitButton">A submit button</label> 
        <input type="submit" name="submitButton" id="submitButton" value="Submit Form" /> 
        <label for="resetButton">A reset button</label> 
        <input type="reset" name="resetButton" id="resetButton"  value="Reset Form" /> 
        <label for="fileSelectField">A file select field</label> 
        <input type="file" name="fileSelectField" id="fileSelectField" value="" /> 
        <label for="hiddenField">A hidden field</label> 
        <input type="hidden" name="hiddenField" id="hiddenField" value="" /> 
        <label for="imageField">An image field</label> 
        <input type="image" name="imageField" id="imageField" value="" src="asterisk.gif" width="23" height="23" /> 
        <label for="pushButton">A push button</label> 
        <input type="button" name="pushButton" id="pushButton"  value="Click Me" /> 
        <label for="pullDownMenu">A pull-down menu</label> 
        <select name="pullDownMenu" id="pullDownMenu" size="1"> 
          <option value="option1">Option 1</option> 
          <option value="option2">Option 2</option> 
          <option value="option3">Option 3</option> 
        </select> 
        <label for="listBox">A list box</label> 
        <select name="listBox" id="listBox" size="3"> 
          <option value="option1">Option 1</option> 
          <option value="option2">Option 2</option> 
          <option value="option3">Option 3</option> 
        </select> 
        <label for="multiListBox">A multi-select list box</label> 
        <select name="multiListBox" id="multiListBox" size="3" multiple="multiple"> 
          <option value="option1">Option 1</option> 
          <option value="option2">Option 2</option> 
          <option value="option3">Option 3</option> 
        </select> 
        <label for="textAreaField">A text area field</label> 
        <textarea name="textAreaField" id="textAreaField" rows="4" cols="50"></textarea> 

    </form> 
  </body> 
</html> 

使用get方法創(chuàng)建表單。 這意味著表單字段名稱和值將被發(fā)送到URL中的服務(wù)器。同時,空的action屬性告訴瀏覽器將表單發(fā)送回來頁。

字段名稱和字段值類似于鍵和關(guān)聯(lián)數(shù)組的值。

大多數(shù)控件也有相關(guān)的標簽元素。此文本向用戶描述字段。每個標簽與其控件相關(guān)聯(lián),使用與其匹配的for屬性對應(yīng)的id屬性在控件元素中。



對空字段操作

當表單字段為空時,某些數(shù)據(jù)不會發(fā)送到服務(wù)器。有時字段作為空字符串發(fā)送;有時沒有字段名稱發(fā)送。

下表說明了各種表單控件的行為當他們“不填寫或選擇:

表單控制 什么時候什么時候沒有填充或選擇
文本輸入字段 將發(fā)送字段名稱以及空值。
文本區(qū)域字段 將發(fā)送字段名稱以及空值。
密碼字段 將發(fā)送字段名稱以及空值。
文件選擇字段 將發(fā)送字段名稱以及空值。
隱藏字段 將發(fā)送字段名稱以及空值。
復選框字段 不發(fā)送任何內(nèi)容。
單選按鈕字段 不發(fā)送任何內(nèi)容。
下拉菜單 始終發(fā)送值。
列表框 不發(fā)送任何內(nèi)容。
多選框 不發(fā)送任何內(nèi)容。
提交按鈕 如果按鈕未被點擊,則不發(fā)送任何內(nèi)容。
圖像字段 如果按鈕未被點擊,則不發(fā)送任何內(nèi)容。
復位按鈕 不發(fā)送任何內(nèi)容。
按鈕 不發(fā)送任何內(nèi)容。
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號