发布后保留单选按钮值

发布于 2024-09-13 19:41:49 字数 91 浏览 5 评论 0原文

您好,

我正在使用 php 页面,我需要在发布页面后保留复选框和单选按钮(选中或未选中)的值。

我怎样才能做到呢?

谢谢

HI

i'm using a php page and i need to keep the value of and check box and radio button (checked or not checked) after post page.

how could i make it?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

大姐,你呐 2024-09-20 19:41:49

首先获取单选按钮的值。

$radiobuttonvalue = $_POST['radiobuttoname']

然后对于每个具有相同名称的单选按钮,执行以下操作

<input type="radio" name="radiobuttonname" value="value" id="radiobuttonname" <?php if($radiobuttonvalue == "value") { echo 'checked="checked"';} ?>

First get the radio button value.

$radiobuttonvalue = $_POST['radiobuttoname']

Then for each radio button with the same name, do this

<input type="radio" name="radiobuttonname" value="value" id="radiobuttonname" <?php if($radiobuttonvalue == "value") { echo 'checked="checked"';} ?>
倾`听者〃 2024-09-20 19:41:49

您需要类似的东西:-

<?php
$postCheckboxName = '';
if (isset($_POST['checkbox_name']) || 'any_value' == $_POST['checkbox_name']) {
    $postCheckboxName = ' checked="checked"';
}
?>
<input type="checkbox" name="checkbox_name" value="any_value"<?php echo $postCheckboxName;?> />

<?php
$postRadioName = '';
if (isset($_POST['radio_name']) || 'any_other_value' == $_POST['radio_name']) {
    $postRadioName = ' checked="checked"';
}
?>
<input type="checkbox" name="radio_name" value="any_other_value"<?php echo $postRadioName;?> />

这段代码应该可以帮助您继续。我基本上是检查复选框/单选元素的 POST 值是否已设置 &相应元素的值是否与我各自元素的值匹配。

希望有帮助。

You need something like:-

<?php
$postCheckboxName = '';
if (isset($_POST['checkbox_name']) || 'any_value' == $_POST['checkbox_name']) {
    $postCheckboxName = ' checked="checked"';
}
?>
<input type="checkbox" name="checkbox_name" value="any_value"<?php echo $postCheckboxName;?> />

<?php
$postRadioName = '';
if (isset($_POST['radio_name']) || 'any_other_value' == $_POST['radio_name']) {
    $postRadioName = ' checked="checked"';
}
?>
<input type="checkbox" name="radio_name" value="any_other_value"<?php echo $postRadioName;?> />

This code should get you going. I'm basically checking whether the POST value of either the checkbox / radio element is set or not & whether the corresponding element's value matches with my respective element's value or not.

Hope it helps.

兔姬 2024-09-20 19:41:49

像这样的事情:

<?php if (isset($_POST['checkbox_name']))?>
<input type="checkbox" checked="checked" value="<?php echo $_POST['checkbox_name'];?>" />
<?php} ?>

<?php if (isset($_POST['radio_name']))?>
<input type="radio" checked="checked" value="<?php echo $_POST['radio_name'];?>" />
<?php} ?>

会发生的情况是,您检查输入变量是否在 $_POST 中,如果是,则将 checked="checked" 添加到输入字段以使其检查过。

Something like this:

<?php if (isset($_POST['checkbox_name']))?>
<input type="checkbox" checked="checked" value="<?php echo $_POST['checkbox_name'];?>" />
<?php} ?>

<?php if (isset($_POST['radio_name']))?>
<input type="radio" checked="checked" value="<?php echo $_POST['radio_name'];?>" />
<?php} ?>

What happens is that you check if the input variables are in the $_POST and if so you add checked="checked" to the input fields to make them checked.

枕梦 2024-09-20 19:41:49

这对我有用,并且是不言自明的

示例代码用法:

<div class="form-group">
    <label class="radio-inline">
        <input type="radio" name="time" value="lunch" <?php if (isset($_POST[ 'time']) && $_POST[ 'time']=='lunch' ){echo ' checked="checked"';}?>>Lunch</label>
    <label class="radio-inline">
        <input type="radio" name="time" value="dinner" <?php if (isset($_POST[ 'time']) && $_POST[ 'time']=='dinner' ){echo ' checked="checked"';}?>>Dinner</label>
</div>

This worked for me, and is self explanatory

sample code usage:

<div class="form-group">
    <label class="radio-inline">
        <input type="radio" name="time" value="lunch" <?php if (isset($_POST[ 'time']) && $_POST[ 'time']=='lunch' ){echo ' checked="checked"';}?>>Lunch</label>
    <label class="radio-inline">
        <input type="radio" name="time" value="dinner" <?php if (isset($_POST[ 'time']) && $_POST[ 'time']=='dinner' ){echo ' checked="checked"';}?>>Dinner</label>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文