POST后如何保持选中单选按钮,复选框和下拉列表 [英] How to remain checked radio button,checkbox and dropdown list as it is after POST
本文介绍了POST后如何保持选中单选按钮,复选框和下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd >
< span class =code-keyword>< html xmlns = http://www.w3 .org / 1999 / xhtml >
< head >
< meta http-equiv = 内容类型 内容 = text / html; charset = utf-8 / > ;
< title > Untitled Document < / title >
< / head >
< body >
<? php
$姓名 = $ mno = $ selected_radio = $ course = $ add = $ fees = ;
if(isset($ _ POST ['submit'] ))
{
if(empty($ _ POST [name]))
{
}
else
< span class =code-summarycomment> {$ name = $ _ POST [ < span class =code-summarycomment> name];
}
if(empty( $ _POST [mno]))
< span class =code-summarycomment> {
}
else {
$ mno = $ _ POST [ mno];
}
如果(空($ _ POST [ 根]))
{
}
else {
$ selected_radio = $ _ POST [ gen];
}
if(空($ _ POST [ch]))
{
}
else {
$ course = $ _ POST [ ch];
}
if(empty($ _ POST [ss]))
{
}
else {
< span class =code-summarycomment>
$ add = $ _ POST [ ss];
}
if(空($ _ POST [费用]))
{
< span class =code-summarycomment>
}
< span class =code-summarycomment> else {
$ fees = $ _ POST [ 费用];
}
}
? >
< 表格 action = pro.php 方法 = 发布 >
名称:< 输入 < span class =code-attribute> type = text name = 名称 align = middle value = <?php echo $ name; ?> / > < br / >
手机号码:< 输入 type = text 值 = <?php echo $ mno;?> < span class =code-attribute> name = mno / > ; < br / >
性别:男:< 输入 type = radio 值 = 男性 名称 = gen id = gen 已检查 = 选中 / >
女:< input type = radio value < span class =code-keyword> = 女性 名称 = gen / > < br < span class =code-keyword> / >
课程:C:< 输入 type = 复选框 value = C name = ch [] / >
C ++:< 输入 type = 复选框 value = C ++ name = ch [] / >
Java:< 输入 type = 复选框 value = Java name = ch [] / >
PHP:< 输入 type = 复选框 value = Php name = ch [] / > < br / >
地址:< textarea name = ss cols = 10 > <? php echo $ add ? > < / textarea > < < span class =code-leadattribute> br / >
费用付款模式:< 选择 name = 费用 id = 费用 >
< 选项 value = 在线 < span class =code-keyword>> 在线< / option >
< 选项 < span class =code-attribute> value = 现金 > 现金< / option >
< 选项 value = 选中 > 检查< / option >
< / select > < br / >
< 输入 < span class =code-attribute> type = submit name = 提交 value = 提交 / >
& lt; 输入 type = 按钮 name = 取消 value = 取消 / >
< / form >
<? php
if(isset($ _ POST ['subm它')))
{
echo 名称 :。$ name。 < br > ;
echoMobile No is:。$ mno。< br > 跨度>;
echo性别为:。$ selected_radio。< br > 跨度>;
if(isset($ _ POST ['submit']))
{
if(isset($ _ POST ['ch']))
{
$ ch = $ _ REQUEST ['ch'];
echo你选择的课程:;
foreach($ _ POST [ch]作为$ value)
{
echo $ value。,;
}}}
echo< br > 地址为:。$ add;
echo< br > 付款方式是:。$ fee;
}
?>
< / body >
< / html >
解决方案
名称 =
MNO =
selected_radio =
<!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=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
$name=$mno=$selected_radio=$course=$add=$fees="";
if(isset($_POST['submit']))
{
if(empty($_POST["name"]))
{
}
else
{$name=$_POST["name"];
}
if(empty($_POST["mno"]))
{
}
else{
$mno=$_POST["mno"];
}
if(empty($_POST["gen"]))
{
}
else{
$selected_radio=$_POST["gen"];
}
if(empty($_POST["ch"]))
{
}
else{
$course=$_POST["ch"];
}
if(empty($_POST["ss"]))
{
}
else{
$add=$_POST["ss"];
}
if(empty($_POST["fees"]))
{
}
else{
$fees=$_POST["fees"];
}
}
?>
<form action="pro.php" method="post">
Name : <input type="text" name="name" align="middle" value="<?php echo $name; ?>" /><br />
Mobile No: <input type="text" value="<?php echo $mno;?>" name="mno" /><br />
Gender : Male :<input type="radio" value="Male" name="gen" id="gen" checked="checked" />
Female :<input type="radio" value="Female" name="gen" /><br />
Course : C :<input type="checkbox" value="C" name="ch[]" />
C++ :<input type="checkbox" value="C++" name="ch[]" />
Java :<input type="checkbox" value="Java" name="ch[]" />
PHP :<input type="checkbox" value="Php" name="ch[]" /><br />
Address : <textarea name="ss" cols="10" ><?php echo $add ?></textarea><br />
Fees Payment Mode :<select name="fees" id="fee">
<option value="Online">Online</option>
<option value="Cash">Cash</option>
<option value="Check">Check</option>
</select><br/>
<input type="submit" name="submit" value="submit" />
<input type="button" name="cancel" value="cancel" />
</form>
<?php
if(isset($_POST['submit']))
{
echo "Name is :".$name."<br>";
echo "Mobile No is :".$mno."<br>";
echo "Gender is :".$selected_radio."<br>";
if(isset($_POST['submit']))
{
if(isset($_POST['ch']))
{
$ch=$_REQUEST['ch'];
echo "You Selected Course :";
foreach($_POST["ch"] as $value)
{
echo $value.",";
}}}
echo "<br>Address is :".$add;
echo "<br>Payment Mode is :".$fees;
}
?>
</body>
</html>
解决方案
name=
mno=
selected_radio=
这篇关于POST后如何保持选中单选按钮,复选框和下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文