gpt4 book ai didi

php - 更改单选按钮上的名称值( Bootstrap )

转载 作者:行者123 更新时间:2023-11-28 05:25:21 25 4
gpt4 key购买 nike

目标是创建四个内联单选按钮,其中一个按钮用于将表单提交到简单的 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 */
}
?>

最佳答案

你有点不对劲。单选按钮必须有一个共同的 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");
}

...等等

关于php - 更改单选按钮上的名称值( Bootstrap ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33218024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com