目标是创建四个内联单选按钮,并带有一个按钮将该表单提交给一个简单的php脚本。问题在于,将名称属性从'optradio'更改为'small'这样的内容会打破按钮之间的切换。更改单选按钮上的名称值(引导程序)
的HTML:
<form action="logo-tshirt.php" method="post">
<label class="radio-inline"><input type="radio" name="small" value="1">S</label>
<label class="radio-inline"><input type="radio" checked name="medium" value="1">M</label>
<label class="radio-inline"><input type="radio" name="large" value="1">L</label>
<label class="radio-inline"><input type="radio" name="extra-large" value="1">XL</label><br />
<input style="margin-top:5px" type="submit" value="Buy With PayPal" name="send" class="btn btn-primary">
</form>
的PHP:
<?php
if($_POST['small'] == 1){
header("Location: http://www.google.com");
}
elseif($_POST['medium'] == 1){
header("Location: http://www.yahoo.com");
}
elseif($_POST['large'] == 1){
header("Location: http://www.bing.com");
}
elseif($_POST['extra-large'] == 1){
header("Location: http://www.bbc.co.uk");
}
else {
header("Location: http://www.theguardian.co.uk");
}
?>
感谢所有的答案。我使用的是AI.G,因为它使用了最少的代码行。这是我的工作代码。
<form action="logo-tshirt.php" method="post">
<label class="radio-inline"><input type="radio" name="optradio" value="small">S</label>
<label class="radio-inline"><input checked type="radio" name="optradio" value="medium">M</label>
<label class="radio-inline"><input type="radio" name="optradio" value="large">L</label>
<label class="radio-inline"><input type="radio" name="optradio" value="extra-large">XL</label><br />
<input style="margin-top:5px" type="submit" value="Buy With PayPal" name="send" class="btn btn-primary">
</form>
的PHP:
<?php
switch ($_POST['optradio']) {
case "small": header("Location: http://www.google.com"); break;
case "medium": header("Location: http://www.yahoo.com"); break;
case "large": header("Location: http://www.bing.com"); break;
case "extra-large": header("Location: http://www.bbc.co.uk"); break;
default:header("Location: http://www.theguardian.co.uk"); /* if $_POST['option'] was none of the above */
}
?>
单选按钮必须具有相同的名称是一伙的,你需要什么做的是改变每个电台的价值,并在PHP中进行比较。 '$ _POST ['my_radio'] =='google'''$ _POST ['my_radio'] =='yahoo'' ... –
为什么你会为同一个广播组保留不同的名字?将名称更改为“大小”,然后将值分别更改为“小,中,大”。然后在你的php'$ _POST ['size']'将有字符串大小。 –