查看: 1069|回复: 6
|
PHP Session - Checkbox,Radio and List/Menu
[复制链接]
|
|
请问我要如何才能像Name textfield那样,按"Change"钮时checkbox, radio和List/menu保留原先用户的选项呢?谢谢!
<?php session_start();
$_SESSION['Name'] = $_POST['Name'];
?>
<html>
<head>
<title>Testing</title>
</head>
<body>
<?php
if ($_POST['submit'] == 'submit')
{
$Name=$_POST['Name'];
if($_POST["hobby1"])
{ foreach($_POST['hobby1'] as $value)
{
$hobby2=join (', ', $_POST['hobby1']);
}
}
echo
("
Name: $Name<br>
Hobby: $hobby2<br>
");
echo
("<form name='frmtest' method = 'post' action='test.php'>
<input type = 'hidden' name = 'Name' value = '$Name'>
<br>
<input type = 'submit' name = 'change' value = 'Change' onclick='buy4D.php'>
</form>");
exit;
}
?>
<form name="frmtest" method="post" action="test.php">
<p>
<strong>Name:</strong>
<input type="text" name="Name" value="<?php echo $_SESSION['Name'] ?>">
<br>
<br>
<strong>Hobby:</strong><br>
<input name="hobby1[]" type="checkbox" value="Gaming">
Gaming
<input name="hobby1[]" type="checkbox" value="Cooking" id="hobby1">
Cooking
<input name="hobby1[]" type="checkbox" value="Swimming">
Swimming<br>
<strong><br>
Sex:</strong><br>
<input type="radio" name="sex" id="radio" value="female">
Female
<input type="radio" name="sex" id="radio2" value="male">
Male <br>
<br>
<strong>Career:</strong>
<select name="career" id="career">
<option value="Lawyer">Lawyer</option>
<option value="Doctor">Doctor</option>
<option value="Engineer">Engineer</option>
</select>
<br>
<br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html> |
|
|
|
|
|
|
|
发表于 22-8-2007 02:27 PM
|
显示全部楼层
可以那样写:
<input name="hobby1[]" type="checkbox" value="Gaming" <?php echo (($_SESSION['hobby1'] == "Gaming")?"SELECTED":""); ?>>
Gaming
<input name="hobby1[]" type="checkbox" value="Cooking" id="hobby1" <?php echo (($_SESSION['hobby1'] == "Cooking")?"SELECTED":""); ?>>
Cooking
<input name="hobby1[]" type="checkbox" value="Swimming" <?php echo (($_SESSION['hobby1'] == "Swimming")?"SELECTED":""); ?>>
Swimming
menu 也一样. |
|
|
|
|
|
|
|

楼主 |
发表于 22-8-2007 05:32 PM
|
显示全部楼层
回复 #2 goatstudio 的帖子
对不起!我是新手。我照您的讲法做了,但还是不行。您可以帮忙试一下吗?万分感激!谢谢! |
|
|
|
|
|
|
|

楼主 |
发表于 23-8-2007 12:18 PM
|
显示全部楼层
回复 #2 goatstudio 的帖子
请各位帮帮忙,好吗?我真的没有ideas继续.......Thanks |
|
|
|
|
|
|
|
发表于 23-8-2007 03:37 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 23-8-2007 05:58 PM
|
显示全部楼层
thanks! 但还是没有头绪 |
|
|
|
|
|
|
|

楼主 |
发表于 25-8-2007 11:40 AM
|
显示全部楼层
Hobby1单选ok!但复选就...请各位指教,谢过了. |
|
|
|
|
|
|
| |
本周最热论坛帖子
|