php checkbox复选框值的获取与checkbox默认值输出方法
时间:2023-11-14 13:41:12
php获取 checkbox复选框值的方法
<html xmlns="https://www.aspxhome.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php获取 checkbox复选框值的方法</title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="复选一">
复选一
</label>
<label>
<input type="checkbox" name="checkbox[]" value="复选二">
</label>
复选二
<label>
<input type="checkbox" name="checkbox[]" value="复选三">
</label>
复选三
<label>
<input type="checkbox" name="checkbox[]" value="复选四">
</label>
复选四
<label>
<input type="submit" name="Submit" value="提交">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo '你选择了:'.implode(',',$value);
//由于checkbox属性,我们必须把checkbox复选择框的名字设置为一个如果checkbox[],这样php才能读取,以数据形式,否则不能正确的读取checkbox复选框的值哦。// aspxhome.net 整理
}
?>
checkbox在php读取值时要用数组形式哦,我们读取这些值用php post获取是以一个array形式哦,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php获取多选框checkbox值</title>
</head>
<body>
<?php
$area_arr = array();
if($_GET['action']=="submit"){
$area_arr = $_POST['area'];
}
echo "您选定的地区为: ";
foreach ($area_arr as $k=>$v){
echo $v." ";
}
?>
<form id="form1" name="form1" method="post" action="?action=submit">
<p>河北
<label>
<input type="checkbox" id="area" name="area[]" value="河北">
</label>
</p>
<p>河南
<label>
<input type="checkbox" id="area[]" name="area[]" value="河南">
</label>
</p>
<p>山西
<label>
<input type="checkbox" id="area[]" name="area[]" value="山西">
</label>
</p>
<p>山东
<label>
<input type="checkbox" id="area[]" name="area[]" value="山东">
</label>
</p>
<p>江苏
<label>
<input type="checkbox" id="area[]" name="area[]" value="江苏">
</label>
</p>
<p>浙江
<label>
<input type="checkbox" id="area[]" name="area[]" value="浙江">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="提交">
</label>
</p>
</form>
</body>
</html>
php checkbox默认选择问题(都是利用的这种原理)
<input name="aspxhome" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>>
标签:php,checkbox,复选框


猜你喜欢
Python切片知识解析
2022-06-07 06:31:58
SQL SERVER 2000通讯管道后复用劫持
2024-01-26 20:13:38
Python提取PDF内容的方法(文本、图像、线条等)
2023-07-03 13:16:59
Python实现Singleton模式的方式详解
2023-08-04 11:48:38
Minio设置文件链接永久有效的完整步骤
2023-06-10 22:26:10

如何正确使用开源项目?
2023-01-29 22:14:57
vue如何在for循环中设置ref并获取$refs
2023-07-02 17:00:04

Django获取该数据的上一条和下一条方法
2022-12-07 13:36:35
Check In和Check Out的多人协作管理
2007-02-03 11:39:00
python获得命令行输入的参数的两种方式
2022-09-30 23:25:02
mysql #1062 –Duplicate entry '1' for key 'PRIMARY'
2024-01-18 22:15:16
Python强大的自省机制详解
2021-06-07 02:07:57

vue tree封装一个可选的树组件方式
2024-05-09 09:53:59

Python3标准库总结
2022-10-22 13:36:47
python解释器安装教程的方法步骤
2023-02-09 14:04:08

Pandas中DataFrame交换列顺序的方法实现
2023-01-21 10:21:08
浅谈keras 模型用于预测时的注意事项
2022-10-16 13:23:04
mysql 各种时间段查询
2010-01-06 13:37:00
python递归&迭代方法实现链表反转
2021-05-04 20:42:04

ACCESS如何打印窗体中当前显示的记录
2008-11-20 16:31:00