Home  >  Article  >  Web Front-end  >  Detailed explanation of the working process of form form

Detailed explanation of the working process of form form

Y2J
Y2JOriginal
2017-05-20 10:27:316914browse

1. Form

1. The role of the form

HTML forms are used to receive different types of user input. When the user submits the form, the data is transmitted to the server, thereby realizing the interaction between the user and the server. Web server interaction.

 2. Working mechanism of the form


  

 3. Form definition (

Tag)

An HTML form is an area containing form elements. Forms are created using the

tag. Forms can contain 1      2      3     

 3. Form Attribute

Action: Specifies where to send form data when the form is submitted. The value of action is: first, a URL (absolute URL/relative URL), generally pointing to a program on the server side. The program receives the data submitted by the form (that is, the form element value) and processes it accordingly. For example,

, when the user submits this form, the server will execute the URL. A general handler named "reg.ashx" on www.cnblogs.com/". Second, use the URL address of the mailto protocol, which will send the form content as an email. This situation is relatively rare , because it requires that the mail-sending program is installed and correctly set up on the visitor's computer. Third, a null value, if the action is empty or not written, means submission to the current page. .

  method:该属性定义浏览器将表单中的数据提交给服务器处理程序的方式。关于method的取值,最常用的是get和post。第一,使用get方式提交表单数据,Web浏览器会将各表单字段元素及其数据按照URL参数格式附在标签的action属性所指定的URL地址后面发送给Web服务器;由于URL的长度限制,使用get方式传送的数据量一般限制在1KB以下。第二,使用post方式,浏览器会将表单数据作为HTTP请求体的一部分发送给服务器。一般来说,使用post方式传送的数据量要比get方式传递的数据量大;根据HTML标准,如果处理表单的服务器程序不会改变服务器上存储的数据,则应采用get方式(比如查询),如果表单处理的结果会引起服务器上存储的数据的变化,则应该采用post方式(比如增删改操作)。第三,其它方式(Head、PUT、DELETE、TRACE 或 OPTIONS等)。其实,最初HTTP标准对各种操作都规定了相应的method,但后来很多都没有被遵守,大部分情况只是使用get或post就OK。关于更多的各种method方式的区别,由于我目前对HTTP协议了解的不多,不敢妄下结论。很多园友的讨论也好像不是很深入,大家争论比较多。

  target:该属性规定在何处显示action属性中指定的URL所返回的结果。取值有_blank(在新窗口中打开)、_self(在相同的框架中打开,默认值)、_parent(在父框架中打开)、_top(在整个窗口中打开)和framename(在指定的框架中打开)。

  title:设置网站访问者的鼠标放在表单上的任意位置停留时,浏览器用小浮标显示的文本。

    enctype:规定在发送到服务器之前应该如何对表单数据进行编码。取值:默认值为 "application/x-www-form-urlencoded",在发送到服务器之前,所有字符都会进行编码(空格转换为 "+" 加号,特殊符号转换为 ASCII HEX 值);“multipart/form-data”:不对字符编码。在使用包含文件上传控件的表单时,必须使用该值。

  name:表单的名称。注意和id属性的区别:name属性是和服务器通信时使用的名称;而id属性是浏览器端使用的名称,该属性主要是为了方便客户端编程,而在css和javascript中使用的。

二、表单元素

  1.单行文本框(input 的type 属性的默认值就是"text")

  以下是单行文本框的主要属性:

    size:指定文本框的宽度,以字符个数为单位;在大多数浏览器中,文本框的缺省宽度是20个字符。

    value:指定文本框的默认值,是在浏览器第一次显示表单或者用户单击按钮之后在文本框中显示的值。

    maxlength:指定用户输入的最大字符长度。

    readonly:只读属性,当设置readonly属性后,文本框可以获得焦点,但用户不能改变文本框中的value。

    disabled:禁用,当文本框被禁用时,不能获得焦点,当然,用户也不能改变文本框的值。并且在提交表单时,浏览器不会将该文本框的值发送给服务器。

  2.密码框 

  3.单选按钮

  使用方式:使用name相同的一组单选按钮,不同radio设定不同的value值,这样通过取指定name的值就可以知道谁被选中了,不用单独的判断。单选按钮的元素值由value属性显式设置,表单提交时,选中项的value和name被打包发送,不显式设置value。

     
    

  4.复选框

  使用复选按钮组,即name相同的一组复选按钮,复选按钮表单元素的元素值由value属性显式设置,表达提交时,所有选中项的value和name被打包发送

不显式设置value。复选框的checked属性表示是否被选中,或者(推荐)checked、readonly等这种一个可选值的属性都可以省略属性值。

      
     
     

  5.隐藏域

  隐藏域通常用于向服务器提交不需要显示给用户的信息。

  6.文件上传

  使用file,则form的enctype必须设置为multipart/form-data,method属性为POST。

  7.下拉框标记创建一个列表框,

 1     

  8.多行文本

  多行文本,cols=“50”、rows=“15”属性表示行数和列数,不指定则浏览器采取默认显示。

1    

  9.标签

   在前可以写普通的文本来修饰,但是单击修饰文本的时候input并不会得到焦点,而用label则可以,for属性指定要修饰的控件的id,;”,然后按下alt+u(了解)。accesskey=“u“,label的另一个属性。注意:要为被修饰的控件设置一个唯一的id。我觉得标签对这两个标签是非常有用的。

1   

   10.

标签

  fieldset标签将控件划分一个区域,看起来更规整。

2    爱好 3      4      5     

  11.提交按钮

  当用户单击的提交按钮时,表单数据会提交给标签的action属性所指定的服务器处理程序。中文IE下默认按钮文本为“提交查询”,可以设置value属性修改按钮的显示文本。 

    

  12.重置按钮

  当用户单击按钮时,表单中的值被重置为初始值。在用户提交表单时,重置按钮的name和value不会提交给服务器。

  13.普通按钮

  普通按钮通常用于单击执行一段脚本代码。

    

  14.图像按钮

  图像按钮的src属性指定图像源文件,它没有value属性。图像按钮可代替,而现在也可以通过css直接将按钮的外观设置为一幅图片

  

三、表单示例

  该示例是使用表单实现的一个简单的注册页面,使用表格布局。

  1 
  2 
  3 
  4     注册页面
  5     
 24 
 25   26       27       28           29               32               35           36           37               40               43           44           45               48               51           52           53               56               70           71           72               75               80           81           82               85               90           91           92               95              104          105          106              109              112          113          114              117              121          122     
 30  用户名:  31               33                   34             
 38  密码:  39               41                   42             
 46  确认密码:  47               49                   50             
 54  请选择市:  55               57                   69             
 73  请选择性别:  74               76                 
 83  请选择职业:  84               86                   87                   88                   89             
 93  请选择爱好:  94               96                 
 97                     你的爱好  98                       99                      100                      101                      102                 
103             
107  备注: 108              110                  111             
115                  116              118                  119                  120             
123      124  125 

【相关推荐】

1. HTML免费视频教程

2. 详解form标签中的method属性

3. 带你掌握HTML中table和form表单

4. 详解html中form表单的参数和属性

5. 带你掌握HTML中table和form表单

The above is the detailed content of Detailed explanation of the working process of form form. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn