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在客户端隐藏密码。密码以无加密的纯文本发送。



例子

<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方法创建表单。 这意味着表单字段名称和值将被发送到URL中的服务器。同时,空的action属性告诉浏览器将表单发送回来页。

字段名称和字段值类似于键和关联数组的值。

大多数控件也有相关的标签元素。此文本向用户描述字段。每个标签与其控件相关联,使用与其匹配的for属性对应的id属性在控件元素中。



对空字段操作

当表单字段为空时,某些数据不会发送到服务器。有时字段作为空字符串发送;有时没有字段名称发送。

下表说明了各种表单控件的行为当他们“不填写或选择:

表单控制 什么时候什么时候没有填充或选择
文本输入字段 将发送字段名称以及空值。
文本区域字段 将发送字段名称以及空值。
密码字段 将发送字段名称以及空值。
文件选择字段 将发送字段名称以及空值。
隐藏字段 将发送字段名称以及空值。
复选框字段 不发送任何内容。
单选按钮字段 不发送任何内容。
下拉菜单 始终发送值。
列表框 不发送任何内容。
多选框 不发送任何内容。
提交按钮 如果按钮未被点击,则不发送任何内容。
图像字段 如果按钮未被点击,则不发送任何内容。
复位按钮 不发送任何内容。
按钮 不发送任何内容。
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号