This form includes common form elements: single-line text box, multi-line text box, single option (radio), multiple options (checkbox), and multi-select menu. Detailed explanation is provided below.
maxlength is an attribute associated with the password text box, which limits the maximum length of the password entered by the user to 10 characters.
The age list box is a list menu, and its named attributes have their own values for selection. Selected is a specific attribute selection element. If an option is attached with this attribute, the item will be listed as the first item when displayed.
The content in the intro text box displays the text, row and column width according to rows and cols.
fave_sport is a group of radio buttons (radio). We need to name the elements according to the group. For example, this group of radio buttons is called fave_sport. The user can only select one, and there is only one value in the sending script.
Like the single option, all multi-option members must also have attributes with the same name, and brackets [] need to be added to the attribute name, so that the value of the multi-option is sent to PHP in the form of an array. Languages is this form.
The checked tag refers to a certain value in single option and multi-option, which is selected by default.
The display screen of the above form is shown in Figure 5-3.
Because the form in the HTML above uses the POST method to transfer data, the data submitted by the user will be saved in the super global array of $_POST or $_REQUEST. We use the The value can be used to process the submitted data.
Submit the data in the above form to the someform.php script. The processing logic of the script is as follows:
Copy the code The code is as follows:
//By judging whether the variable name of the button is defined in $_POST, if so, it means that the form has been submitted
if(isset($_POST["btn_submit"])){
if (empty($_POST['username'])){
echo "You did not enter a username";
exit(0);
}
if (empty($_POST['password' ])){
echo "You did not enter your password: ";
exit(0);
}
echo "Your username: ".$_POST['user_name']."
";
echo "Your password (plain text): ".$_POST['password']."
";
echo "Your age: ".$_POST['age'] ."
";
if (!empty($_POST['languages'])){
echo "The language you selected is:";
//Handle the checkbox button of the user's selected interests The resulting array
foreach ($_POST['languages'] as $lang){
echo $lang. " ";
}
} else {
echo "You did not enter any interest Hobby";
}
if (!empty($_POST['develop_ide'])){
echo "The development tool you are using is:";
//Handle user multiple selection of development tools Array generated by menu
foreach ($_POST['develop_ide'] as $ide){
echo $ide. " ";
}
} else {
echo "You did not choose to develop Tools";
}
echo "Your self-introduction: ".nl2br($_POST['intro'])."
";//nl2br(), in the string Insert HTML newline character (
) before each new line (n)
";
echo "Web page hidden value (passed through hidden tag value): ".$_POST['from'] ."
";
}
?>
Instructions: Use POST to submit the form and transfer the form data through the header part of the HTTP protocol. Theoretically, the size of the data is unlimited. upper limit. However, when using PHP for POST submission, the file size is limited by the PHP configuration file (php.ini). We can modify the post_max_size parameter in the php.ini file and change the default 2M bytes to the size we need. However, due to the characteristics of the HTTP protocol, this value should not be set too large, and the maximum is 8M.
http://www.bkjia.com/PHPjc/324566.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324566.htmlTechArticleA complete form processing Next we will create a complex form, the code is as follows. Copy the code The code is as follows: form action="someform.php" method="post" table width="541" bor...