Php retrieves check box text box, password domain, hidden domain, Button, text domain value instance

Source: Internet
Author: User
Tags php tutorial

The check box can be used to select multiple items. When entering some forms, the viewer sometimes needs to select multiple items (such as interests and hobbies)
Check boxes usually exist at the same time. To facilitate value transfer, the name can be defined as an array: <input type = "checkbox" name = "chkbox []" value = "chkbox1 & prime;>
On the return page, you can use the count () function to calculate the size of the array and use the for loop statement to output the value of the selected check box.

<? Php Tutorial
If ($ _ post [mrbook]! = Null )){
Echo "the result you selected is :";
For ($ I = 0; $ I <count ($ _ post [mrbook]); $ I ++)
Echo $ _ post [mrbook] [$ I]. "& nbsp;"; // cyclically outputs the selected book category
  }
?>


<Form name = "form1 & prime; method =" post "action =" index. php ">
<Table width = "445 & prime; cellpadding =" 0 & prime; cellspacing = "0 & prime;>
<Tr>
<Td width = "443 & prime; height =" 41 & prime; align = "center" valign = "top">
Your favorite types of books:
<Input type = "checkbox" name = "mrbook []" value = "entry class">
Entry class
<Input type = "checkbox" name = "mrbook []" value = "case Class">
Case
<Input type = "checkbox" name = "mrbook []" value = "">
Explanations
<Input type = "checkbox" name = "mrbook []" value = "typical instance class">
Typical instance type
<Br>
<Input type = "submit" name = "submit" value = "submit"> </td>
</Tr>
</Table>
</Form>

Obtains the text box, password field, hidden field, button, and text field values.
The methods used to obtain the values of the text box, password field, hidden field, button, and text field are the same. The name attribute is used to obtain the desired value. Therefore, do not repeat the name value to avoid obtaining the wrong value.
The following example shows how to use $ _ post [] to obtain the values of the text box, password field, hidden field, button, and text field:

Instance code:

<? Php
If ($ _ post ["submit"] = "login") {// determine whether to submit information
Echo "the password you entered is:". $ _ post [user]. "<br> The password is:". $ _ post [pw]; // enter the submitted data.
}
?>

<Form action = "index. php" method = "post" name = "zero"> // create a form
Username: <input type = "text" name = "user" size = "20 & prime;/> <br>
Password: <input type = "password" name = "pw" size = "20 & prime;/> <br>
<Input type = "submit" name = "submit" value = "login"/>
</Form>
Display result:
The password you entered is: zero
Password: 123456

User name:
Password:
 

2. Obtain the value of the single button
Radio single-choice buttons are generally grouped and have the same name value and different value values. Only one value can be selected in a group of single-choice buttons at the same time.
The following describes how to obtain the value of a single shard through a specific instance.

Instance code:

<? Php
If ($ _ post ["submit"] = "submit") {// determines whether to submit data.
Echo "your gender is:". $ _ post ["sex"];
}
?>
<Form action = "index. php" method = "post" name = "zero">
Gender:
<Input type = "radio" name = "sex" value = "male" checked/> male
<Input type = "radio" name = "sex" value = "female"/> Female
<Input type = "submit" name = "submit" value = "submit"/>
</Form>


Output result:
Your gender is: Male

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