Home  >  Article  >  Backend Development  >  Basic PHP Tutorial: Form Get the value of the radio button

Basic PHP Tutorial: Form Get the value of the radio button

黄舟
黄舟Original
2016-12-21 09:52:242044browse

定义和用法 当用户从若干给定的的选择中选取其一时,就会用到单选框。
语法<input type="radio" name="sex" value="male"> 男
<input type="radio" name="sex" value="female"> 女
参数说明type 表单的类型。其中的radio表示单选按钮。
name 选项的名称。可以自己定义名称。
value 是单选按钮的值,上例中“男”对应的值就是 male,“女”对应的值就是"female"
实例<?php
if($_POST[Submit]=="提交"){ //如果用户提交了数据
echo "你选择的是".$_POST[Sex];   //输出单选按钮的值
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>获取单选按钮的值-www.dushuwu.net</title>
</head>
<body>
<form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>">
男性:
<input type="radio" checked="checked" name="Sex" value="male">
<br>
女性:
<input type="radio" name="Sex" value="female">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>

 以上就是php基础教程:表单 获取获取单选按钮的值的内容,更多相关内容请关注PHP中文网(www.php.cn)! 


Statement:
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