PHP Form Submission example explain _php skills

Source: Internet
Author: User

This article for you to share a particularly simple PHP form submission instance, the specific implementation steps are as follows:

The instance code is as follows:

<form action= "someform.php" method= "POST" > <table width= "541" border= "0" > <tr> <td width= "26%" & gt; name:</td> <td width= "74%" ><input type= "text" name= "username" value= "Raymond" id= "username"/>< /td> </tr> <tr> <td> password:</td> <td><input type= "password" name= "password" maxlen Gth= "id=" "Password"/></td> </tr> <tr> <td> age:</td> <td> <select na Me= "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> </selec t> </td> </tr> <tr> <td valign= "Top" > Self introduction:</td> <td><textarea name= "in Tro "rows=" 3 "cols=" id= "Intro" > Please input your self-introduction </textarea></td> </tr> <tr> <td><br /> Sports Hobby: </td> &LT;td><input type= "Radio" name= "Fave_sport" value= "tennis" checked> Tennis <input type= "Radio" name= "Fave_sport" "Value=" Football "> Soccer <input type=" Radio "name=" Fave_sport "value=" Baseball "> Basketball <input type=" Radio "name = "Fave_sport" value= "Polo" > Bowling </td> </tr> <tr> <td> development language:</td> <td><i Nput name= "from" type= "hidden" id= "from" value= "registration Form" > <input type= "checkbox" Name= "languages[" "value=" PHP chec ked id= "languages[]" > PHP <input type= "checkbox" Name= "languages[]" value= "java" id= "languages[]" > Java <i Nput type= "checkbox" Name= "languages[]" value= "Perl" id= "languages[" "> Perl <input type=" checkbox "Name=" Languages[] "value=" CPP id= "languages[]" > C + + <input type= "checkbox" Name= "languages[" "value=". Net "id=" Languages[] ">. NET <input type=" checkbox "Name=" languages["" Value= "" Delphi "Id=" Languages["" > Delphi </td& 
 Gt </tr> <tr> &LT;TD Valign= "Top" ><br> <label> development tools:</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 > </tr> <tr> <td valign= "Top" > </td> <td><input type= "Submit" Name= "btn_s" 
 Ubmit "value="/></td> </tr> </table> </form>

This form includes common form elements: Single-line text boxes, multi-line text boxes, single options (radio), multiple options (checkboxes), and multiple-selection menus.

The following is a detailed description:

maxlength is the property associated with the password text box, which restricts the maximum length of 10 characters that a user enters a password.

The Age list box is a list menu that has its own values under its named attribute. Selected is a specific attribute selection element that, if an option attaches the attribute, is displayed as the first item when displayed.

Intro the contents of the text box to display the text, rows, and columns according to rows and cols.

Fave_sport is a set of radio buttons (radio), we want to name the element by group, such as this group of radio buttons are called Fave_sport, the user can only select one, the sending script end only has a value.

As with a single option, all multiple-option members must have attributes with the same name, and the property name needs to be added with parentheses [] so that the value of the multiple option is sent to the php,languages as an array in this form.

The checked label refers to a single option and a value in multiple options, which is already selected by default.

The display of the above form appears as shown in the picture

Since the form form in the HTML above uses the Post method to pass data, the data submitted by the user is saved to the $_post or $_request Super Global array, and we can process the submitted data based on the values in the $_post array.

Submit the data in the above form to the someform.php script, which has the following processing logic:

By determining whether the variable name of the button is defined in $_post, if there is an indication that the form has been submitted 
if (Isset ($_post["Btn_submit")) {if (Emptyempty ' $_post[']) 
) { 
echo "you did not enter a username"; 
Exit (0); 
} 
if (emptyempty ($_post[' password ')) { 
echo "you did not enter a password:"; 
Exit (0); 
} 
echo "Your username:". $_post[' user_name '. "" 
; 
echo "Your password (plaintext):". $_post[' password '. "" 
; 
echo "Your Age:". $_post[' ages '. "" 
; 
if (!emptyempty ($_post[' languages ')) { 
echo "The language you have chosen is:"; 
The array 
foreach ($_post[' languages '] as $lang) {echo $lang) generated by the checkbox button that handles the user's choice of interest 
. 
else { 
echo "you did not enter any hobbies"; 
} 
if (!emptyempty ($_post[' develop_ide ')) { 
echo "the development tool you are using is:"; 
Handle the array 
foreach ($_post[' develop_ide '] as $ide) {echo $ide generated by the user's multiple selection development Tools menu 
. " "; 
} 
} else { 
echo "You did not select development tool"; 
} 
echo "Your self-introduction:". NL2BR ($_post[' intro '). " <br/> ";//nl2br () inserts an HTML newline character (<br/>) before each new line (n) in the string 
; 
echo "Web page hidden value (passed by hidden label value):". $_post[' from '. "" 
; 
} 
? >

The above is for you to share the PHP form submission example, to help you better learn PHP form submission, I hope everyone has harvested.

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.