Home php教程 php手册 php获取复选框 文本框、密码域、隐藏域、按钮、文本域值

php获取复选框 文本框、密码域、隐藏域、按钮、文本域值

May 25, 2016 pm 04:46 PM
password button text

复选框能够进行项目的多项选择,浏览者在填写一些表单时,有时需要选择多个项目(如:兴趣爱好等)

复选框一般是多个同时存在,为了便于传值,name的名字可以定义为数组形式:

在返回页面中可以用count()函数计算数组的大小,结合for循环语句输出选择的复选框的值:

<?php 
	  if(($_post[mrbook]!= null)){  
	   echo "您选择的结果是:"; 
	   for($i = 0;$i<count($_post[mrbook]);$i++) 
	    echo $_post[mrbook][$i]."  ";  //循环输出用户选择的图书类别 
	  } 
	 
	<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"> 
	     您喜欢的图书类型: 
	       <input type="checkbox" name="mrbook[]" value="入门类"> 
	     入门类 
	     <input type="checkbox" name="mrbook[]" value="案例类"> 
	        案例类 
	        <input type="checkbox" name="mrbook[]" value="讲解类"> 
	        讲解类 
	        <input type="checkbox" name="mrbook[]" value="典型实例类"> 
	      典型实例类 
	      <br> 
	      <input type="submit" name="submit" value="提交"></td> 
	  </tr> 
	</table> 
	</form> 
Copy after login

获取文本框、密码域、隐藏域、按钮、文本域的值

获取文本框、密码域、隐藏域、按钮、文本域的值的方法都是相同的,都是使用name属性来获取想用的value值,所以在定义name值时尽量不要重复,以免获取错误的值.

下面我们通过一个实例来说明用$_post[]获取获取文本框、密码域、隐藏域、按钮、文本域的值的具体方法:

<?php 
	if($_post["submit"]=="登陆"){     //判断是否提交信息 
	 echo"您输入的密码为:".$_post[user]."<br>密码为:".$_post[pw];   //输入提交数据 
	} 
	 
	<form action="index.php" method="post" name="zero">   //建立form表单 
	  用户名:<input type="text" name="user" size="20&prime;/><br> 
	  密码:<input type="password" name="pw" size="20&prime;/><br> 
	  <input type="submit" name="submit" value="登陆"/> 
	</form> 
	//显示结果: 
	//您输入的密码为:zero 
	//密码为:123456 
	//用户名: 
	//密码: 
Copy after login

获取单选框按钮的值

radio单选框按钮一般是成组出现的,具有相同name值和不同的value值,在一组单选按钮中同一时间只能选中一个值.

下面通过具体的实例来解释如何获取单选框的值,实例代码:

<?php 
	if($_post["submit"]=="提交"){   //判断是否提交数据 
	 echo"您的性别是:".$_post["sex"]; 
	} 
	 
	 <form action="index.php" method="post" name="zero"> 
	性别: 
	<input type="radio" name="sex" value="男" checked />男 
	<input type="radio" name="sex" value="女"/>女 
	<input type="submit" name="submit" value="提交"/> 
	</form> 
	//输出结果: 
	//您的性别是:男 
Copy after login

教程链接:

随意转载~但请保留教程地址★

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? How to solve the problem that Windows 11 prompts you to enter the administrator username and password to continue? Apr 11, 2024 am 09:10 AM

When using Win11 system, sometimes you will encounter a prompt that requires you to enter the administrator username and password. This article will discuss how to deal with this situation. Method 1: 1. Click [Windows Logo], then press [Shift+Restart] to enter safe mode; or enter safe mode this way: click the Start menu and select Settings. Select "Update and Security"; select "Restart Now" in "Recovery"; after restarting and entering the options, select - Troubleshoot - Advanced Options - Startup Settings -&mdash

How to set router WiFi password using mobile phone (using mobile phone as tool) How to set router WiFi password using mobile phone (using mobile phone as tool) Apr 24, 2024 pm 06:04 PM

Wireless networks have become an indispensable part of people's lives in today's digital world. Protecting the security of personal wireless networks is particularly important, however. Setting a strong password is key to ensuring that your WiFi network cannot be hacked by others. To ensure your network security, this article will introduce in detail how to use your mobile phone to change the router WiFi password. 1. Open the router management page - Open the router management page in the mobile browser and enter the router's default IP address. 2. Enter the administrator username and password - To gain access, enter the correct administrator username and password in the login page. 3. Navigate to the wireless settings page - find and click to enter the wireless settings page, in the router management page. 4. Find the current Wi

How to use Passkey for your Microsoft account How to use Passkey for your Microsoft account Feb 19, 2024 am 11:03 AM

Passkey is a more advanced and secure way to log in and can be used with a Microsoft account. This article will guide you how to use Passkey in your Microsoft account, introduce its advantages and the differences with passwords. Before we get into the details, we emphasize that if you frequently forget your passwords or need to log in quickly, Passkey will generally be better for you. What is Passkey? How are they different from passwords? Passwords are an advanced and secure authentication method that can replace traditional password logins. Each application has a unique key, ensuring security and preventing threats like phishing. Users can confirm their identity via email and password, or use facial recognition, fingerprint or security key

Incorrect password, beware BitLocker warning Incorrect password, beware BitLocker warning Mar 26, 2024 am 09:41 AM

This article will explore how to solve the problem of wrong password, especially the need to be careful when dealing with BitLocker warnings. This warning is triggered when an incorrect password is entered multiple times in BitLocker to unlock the drive. Usually, this warning occurs because the system has a policy that limits incorrect login attempts (usually three login attempts are allowed). In this case, the user will receive an appropriate warning message. The complete warning message is as follows: The password entered is incorrect. Please note that continuously entering incorrect passwords will cause the account to be locked. This is to protect the security of your data. If you need to unlock your account, you will need to use a BitLocker recovery key. The password is incorrect, beware the BitLocker warning you receive when you log in to your computer

How to Remove Windows 10 Lock Screen Password Now How to Remove Windows 10 Lock Screen Password Now Jan 09, 2024 pm 03:33 PM

After upgrading the win101909 system, some friends may want to cancel their computer lock screen password. If you don’t know what to do, I think we can find the account options in the computer’s settings window. Let’s take a look at the specific methods. How to cancel the lock screen password in win101909: 1. First press Win+I to open the settings interface. 2. Then find the account--login option, and then set it as shown. How to cancel power-on password login in win101909: 1. Execute regedit during running to open the registry and navigate to the following path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\Cu

Tutorial on changing wifi password on mobile phone (simple operation) Tutorial on changing wifi password on mobile phone (simple operation) Apr 26, 2024 pm 06:25 PM

Wireless networks have become an indispensable part of our lives with the rapid development of the Internet. In order to protect personal information and network security, it is very important to change your wifi password regularly, however. To help you better protect your home network security, this article will introduce you to a detailed tutorial on how to use your mobile phone to change your WiFi password. 1. Understand the importance of WiFi passwords. WiFi passwords are the first line of defense to protect personal information and network security. In the Internet age, understanding its importance can better understand why passwords need to be changed regularly. 2. Confirm that the phone is connected to wifi. First, make sure that the phone is connected to the wifi network whose password you want to change before changing the wifi password. 3. Open the phone’s settings menu and enter the phone’s settings menu.

Why won't my laptop start up after pressing the power button? Why won't my laptop start up after pressing the power button? Mar 10, 2024 am 09:31 AM

There could be several reasons why your Windows laptop won't boot. Memory failure, dead battery, faulty power button, or hardware issues are all common causes. Here are some solutions to help you resolve this issue. Laptop won't turn on after pressing the power button If your Windows laptop still won't turn on after pressing the power button, here are some steps you can take to resolve the issue: Is your laptop fully charged? Perform a hard reset to clean your laptop Reseat the memory Transparent CMOS type battery Take your laptop for repair. 1] Is your laptop fully charged? The first thing to do is to check if your laptop is fully charged. Laptop won't start if battery is drained

What does iPhone 16 look like? What changes are there in iPhone 16? What does iPhone 16 look like? What changes are there in iPhone 16? Apr 07, 2024 pm 05:10 PM

After the release of the iPhone 15 series, there have been constant revelations about the appearance and configuration of Apple’s new iPhone 16. What does iPhone 16 look like? Is there any improvement in iPhone 16? Recently, an overseas blogger showed off the design of the iPhone 16 series. The overall design is basically the same as the iPhone 15 series. As you can see from the picture, the entire iPhone 16 series is equipped with a new "shoot" button as standard, allowing users to take photos more conveniently. In addition, other design details are still unknown. The message shows that this new button will be used to shoot videos and is located below the power button. Previous news has mentioned that it may be a capacitive solid-state button, but recent reports indicate that it should still be a

See all articles