Php example of form submission. For more information about how to submit a php Tutorial form for beginners, see. The following code creates a complex form. The code below is used to copy the form submission instance of a php Tutorial for a super simple beginner. if you need it, refer to it. The following code creates a complex form.
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.
Bytes
Maxlength is an attribute associated with the password text box. it limits the maximum length of a password to 10 characters.
Bytes
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.
Bytes
The content in the intro text box displays text, row, and column width according to rows and cols.
Bytes
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.
Bytes
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.
Bytes
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. -3 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']." "; } ?> |
Bytes. The following code creates a complex form. The code is as follows...