Php example of form submission

Source: Internet
Author: User
Tags php example php script ultraedit
The following code creates a complex form.
The code is as follows: Copy code
<Form action = "someform. php" method = "post">
<Table width = "541" border = "0">
& Lt; td width = "26%" & gt; Name: & lt;/td & gt;
<Td width = "74%"> <input type = "text" name = "username" value = "raymond" id = "username"/> </td>
<Td> Password: </td>
<Td> <input type = "password" name = "password" maxlength = "10" id = "password"/> </td>
<Td> Age: </td>
<Select name = "age">
<Option value = "> 16"> less than 16 </option>
<Option value = "16-30" selected> 16-30 </option>
<Option value = "31-50"> 31-50 </option>
<Option value = "51-80"> 51-80 </option>
<Td valign = "top"> Self-introduction: </td>
<Td> <textarea name = "intro" rows = "3" cols = "50" id = "intro"> enter your own profile </textarea> </td>
<Td> <br/>
Sports hobbies: </td>
<Td> <input type = "radio" name = "fave_sport" value = "tennis" checked>
<Input type = "radio" name = "fave_sport" value = "football">
<Input type = "radio" name = "fave_sport" value = "baseball">
<Input type = "radio" name = "fave_sport" value = "polo">
Bowling </td>
<Td> Development Language: </td>
<Td> <input name = "from" type = "hidden" id = "from" value = "registry ticket">
<Input type = "checkbox" name = "ages []" value = "php" checked id = "ages []">
<Input type = "checkbox" name = "ages []" value = "java" id = "ages []">
<Input type = "checkbox" name = "ages []" value = "perl" id = "ages []">
<Input type = "checkbox" name = "ages []" value = "cpp" id = "ages []">
C ++
<Input type = "checkbox" name = "ages []" value = ". net" id = "ages []">
<Input type = "checkbox" name = "ages []" value = "delphi" id = "ages []">
Delphi </td>
<Td valign = "top"> <br>
<Label> Development Tool: </label> </td>
<Td> <select name = "develop_ide []" size = "5" multiple id = "develop_ide []">
<Option value = "ZDE" selected> Zend Studio </option>
<Option value = "Eclipse"> Eclipse </option>
<Option value = "Editplus"> Editplus </option>
<Option value = "Ultraedit"> Ultraedit </option>
<Option value = "Other"> Other </option>
</Select> </td>
<Td valign = "top"> & nbsp; </td>
<Td> <input type = "submit" name = "btn_submit" value = "submit"/> </td>
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 shows the figure above.
Figure 5-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: Copy code
// 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']). "<br/>"; // nl2br (), insert an HTML line break before each new line (n) in the string (<br/>)
Echo "webpage hidden value (passed through the hidden tag value):". $ _ POST ['from']."
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.