Php complete form processing implementation code _ PHP Tutorial

Source: Internet
Author: User
Php complete form processing implementation code. After processing a complete form, we will create a complex form. the code is as follows. The copy code is as follows: formactionsomeform. phpmethodposttablebor a complete form processing
The following code creates a complex form.

The code is as follows:




This form includes common form elements: single-line text box, multi-line text box, single option (radio), multi-option (checkbox), and multi-choice menu. The following is a detailed description.
Maxlength is an attribute associated with the password text box. it limits the maximum length of a password to 10 characters.
The age list box is a list menu with its own values under its naming attributes. Selected is a specific attribute selection element. If an option is attached with this attribute, this attribute is listed as the first item during display.
The content in the intro text box displays text, row, and column width according to rows and cols.
Fave_sport is a set of single-choice buttons (radio). we need to name the elements by group. for example, each group of single-choice buttons is named fave_sport. you can select only one, the sending script also has only one value.
Like a single option, all multi-option members must have attributes of the same name, and the attribute name must be added with brackets []. in this way, the values of multiple options are sent to PHP in an array, ages is in this form.
The checked tag refers to a value in a single option and multiple options. it is selected by default.

The Figure 5-3 in the form above is shown.

Because the form in the preceding HTML uses the POST method to transmit data, the data submitted by the user is saved to the Super global array of $ _ POST or $ _ REQUEST, we can process submitted data based on the value in the $ _ POST array.

Submit the data in the preceding form to the someform. php script. the processing logic of this script is as follows:

The code is as follows:


// Determine whether the variable name of the button is defined in $ _ POST. If yes, the form has been submitted.
If (isset ($ _ POST ["btn_submit"]) {
If (empty ($ _ POST ['username']) {
Echo "you have not entered the user name ";
Exit (0 );
}
If (empty ($ _ POST ['password']) {
Echo "you have not entered the password :";
Exit (0 );
}
Echo "Your username:". $ _ POST ['User _ name']."
";
Echo "your password (plaintext):". $ _ POST ['password']."
";
Echo "your age:". $ _ POST ['age']."
";
If (! Empty ($ _ POST ['ages ']) {
Echo "the language you selected is :";
// Process the array generated by the checkbox button of interest selected by the user
Foreach ($ _ POST ['ages '] as $ lang ){
Echo $ lang ."";
}
} Else {
Echo "you have not entered any interests ";
}
If (! Empty ($ _ POST ['develop _ ide ']) {
Echo "your development tool is :";
// Process the array generated by the menu of multiple development tools selected by the user
Foreach ($ _ POST ['develop _ ide '] as $ ide ){
Echo $ ide ."";
}
} Else {
Echo "you have not selected a development tool ";
}
Echo "your self-introduction:". nl2br ($ _ POST ['Intro'])."
"; // Nl2br (), insert the HTML line break (
)
";
Echo "webpage hidden value (passed through the hidden tag value):". $ _ POST ['from']."
";
}
?>


Note: The form is submitted in POST mode and the form data is transmitted through the header part of the HTTP protocol. Theoretically, the data size is unlimited. However, when using PHP for POST submission, the file size is subject to the PHP configuration file (php. ini) restrictions, we can modify php. the post_max_size parameter in the INI file can be changed to the default size of 2 MB. However, due to the characteristics of the HTTP protocol, this value should not be too large, and the maximum value is 8 MB.

The following code creates a complex form. The code is as follows: form action = "someform. php" method = "post" table width = "541" bor...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.