HTML form
What is a form
##The form is to collect different types of user input, such as:
- Website registration
- Login
- Post resume
- Forum post
- Reply S vote etc
##HTML Form
A form is an area containing form elements. A web page may have multiple forms, but a form corresponds to a form area, and can only submit the form items of the current form area.
The form element allows the user to enter content in the form, such as: text area (textarea) , drop-down lists, radio-buttons, checkboxes, etc.
The form uses the form tag <form> to set:
##<form method="Transmission method" action="Server file address">.input element
</form>
action is used to configure where the form data is sent for processing. It is usually the address of a dynamic script, such as the address of a PHP file. login.php
method can be GET or POST (if not set, the system defaults to GET, but in most cases We use POST and GET to submit in the form of parameters. Users can directly see the submitted parameters. Post uses the HTTP post mechanism to place each field in the form and its content in the HTML HEADER and transmit it to the URL address pointed to by the ACTION attribute. Can't see this process)
##HTML Form - Input Element
Text field
The text field is set through the <input type="text"> tag. When the user types letters, numbers, etc. in the form, the text field is used.
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form> 文本域: <input type="text" name="firstname"><br> 文本域: <input type="text" name="lastname"> </form> </body> </html>
The browser displays the following:
Password field
##The password field is defined by the tag <input type="password">:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form> 姓名: <input type="text" name="firstname"><br> 密码: <input type="password" name="lastname"> </form> </body> </html>The browser displays as follows:
Note: Password field characters will not be displayed in plain text, but will be replaced by asterisks or dots.
Radio button
##<input type="radio"> tag defines the form radio button Options<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
<form>
<input type="radio" name="sex" value="male">男<br>
<input type="radio" name="sex" value="female">女
</form>
</body>
</html>
The browser displays the following:
Checkbox
<input type="checkbox"> defines a checkbox. The user needs to select from a number of given Select one or several options from the selection.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <input type="checkbox" name="vehicle" value="自行车">自行车 <input type="checkbox" name="vehicle" value="汽车">汽车 <input type="checkbox" name="vehicle" value="飞机">飞机 <input type="checkbox" name="vehicle" value="轮船">轮船 </body> </html>
The browser displays as follows:
##Submit button
<input type="submit"> defines the submit button.When the user clicks the confirm button, the content of the form will be transferred to another file. The form's action attribute defines the file name of the destination file. The file defined by the action attribute usually performs related processing on the input data received. :<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form name="input" action="action.php" method="post"> 用户名 <input type="text" name="user"><br/> 密 码 <input type="password" name="user"> <input type="submit" value="Submit"> </form> </body> </html>The browser displays as follows:#If you type a few letters in the text box above and then click the confirm button, the input data will Sent to the "action.php" page as a post. This page will display the entered results.
HTML form tag
Tags | Description |
<form> | Define the form for user input |
<input> | Define the input field |
<textarea> | Define the text area (a multi-line input control) |
<label> | Defines the label of the <input> element, usually the input title |
<fieldset> | Defines a set of related form elements and uses an outer frame to enclose them |
< ;legend> | Defines the title of the <fieldset> element |
<select> | Defines the drop-down option list |
<optgroup> | Define the option group |
Define the options in the drop-down list |
Define a click button | |
Specifies a predefined input control option list | |
Defines the key pair generator field of the form | |
Define a calculation result |