目标是创建四个内联单选按钮,并使用一个按钮将表单提交到一个简单的PHP脚本。问题是将name属性从'optradio'更改为'small'会破坏按钮之间的切换。
html:
<ion-view align-title="left">
<h1 style="margin-left:100px" class="title">
<img class="title-image" src="http://www.ionicframework.com/img/ionic-logo-white.svg" width="123" height="43" />
</h1>
<h1 class="title">Titled Text</h1>
php:
<ion-nav-buttons side="left">
<img class="title-image" src=".../ionic-logo-white.svg" width="30" height="43" /></h1>
</ion-nav-buttons>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
感谢所有答案。我使用的是AI.G,因为它使用了最少的代码行。这是我的工作代码。
<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");
}
?>
答案 0 :(得分:3)
你有点不对劲。单选按钮必须具有公共name
,其value
实际上是发送到服务器的。示例:
<form action="a.php" method="post">
<label class="radio-inline"><input type="radio" name="buy" value="small">S</label>
<label class="radio-inline"><input type="radio" name="buy" checked value="medium">M</label>
<label class="radio-inline"><input type="radio" name="buy" value="large">L</label>
<label class="radio-inline"><input type="radio" name="buy" value="extra-large">XL</label><br />
<input style="margin-top:5px" type="submit" value="Buy With PayPal" name="send" class="btn btn-primary">
</form>
现在您可以通过$ _POST
提取所选值if ($_POST['buy'] == 'small' ){
header("Location: http://www.google.com");
}
...等
答案 1 :(得分:2)
所有无线电应具有相同的名称但值不同:
<label class="radio-inline"><input type="radio" name="option" value="small">S</label>
<label class="radio-inline"><input type="radio" checked name="option" value="medium">M</label>
<label class="radio-inline"><input type="radio" name="option" value="large">L</label>
<label class="radio-inline"><input type="radio" name="option" value="extra-large">XL</label>
现在使用开关检查它们:
switch ($_POST['option']) {
case "small": /* redirect to google */ break;
case "medium": /* redirect to yahoo */ break;
/* etc... */
default:
/* if $_POST['option'] was none of the above */
/* redirect to somewhere else */
}