来自提交表单值的回显,具有不同的ID

时间:2011-08-22 04:33:06

标签: php echo

我有一个提交表格,其中有三个

其中两个是可以的,我使用一个ID来提交所有要提交的值

但其中我现在正在努力的其中一个当然是具有不同价值的那个,而且选择形式也有不同的ID,让我迷惑如何回应它。

<form action="" method="post">
  <div data-role="fieldcontain">
    <fieldset data-role="controlgroup" data-type="horizontal" >
        <legend>เลือกช่อง</legend>
            <input type="radio" name="radio-choice-1" id="radio-choice-1" value="ch41" checked="checked" />
            <label for="radio-choice-1">number 1</label>

            <input type="radio" name="radio-choice-1" id="radio-choice-2" value="ch80" />
            <label for="radio-choice-2">number 2</label>

            <input type="radio" name="radio-choice-1" id="radio-choice-3" value="ch44"  />
            <label for="radio-choice-3>"number 3</label>

            <input type="radio" name="radio-choice-1" id="radio-choice-4" value="ch42"  />
            <label for="radio-choice-4">number 4</label>

            <input type="radio" name="radio-choice-1" id="radio-choice-5" value="ch83"  />
            <label for="radio-choice-5">number 5</label>
    </fieldset>
</div> 
</form>

这就是我想要回应的内容

<video width="5%" height="5%" src="http://mydomain:<?php echo $_POST["radio-choice-1"]; ?>-<?php echo $_POST["date"]; ?>-<?php echo $_POST["time"]; ?>" alt="" controls="" tabindex="0">

问题出在"radio-choice-#"

因为ID上有5个数字


这是示例

            <input type="radio" name="radio-choice-1" id="radio-choice-2" value="ch80" />
        <label for="radio-choice-2">number 2</label>

        <input type="radio" name="radio-choice-1" id="radio-choice-3" value="ch44"  />
        <label for="radio-choice-3>"number 3</label>

        <input type="radio" name="radio-choice-1" id="radio-choice-4" value="ch42"  />
        <label for="radio-choice-4">number 4</label>

        <input type="radio" name="radio-choice-1" id="radio-choice-5" value="ch83"  />
        <label for="radio-choice-5">number 5</label>

所以如果他们选择菜单号5

我想在这里回应

<video width="5%" height="5%" src="http://mydomain:<?php echo $_POST["the value of number 5"]; ?">

1 个答案:

答案 0 :(得分:1)

您实际从单选按钮获取值的代码已经正确无误。您可以使用以下内容来保持数据更有条理,并且能够获取您正在使用的“页面”编号。

<?php
$items = array('ch41', 'ch80', 'ch44', 'ch42', 'ch83');
$page = array_search((empty($_POST['choice']) ? 'ch41' : $_POST['choice']), $items) + 1; // Change 'ch41' to whatever the default page is
// To name the labels, you can add keys for your values like so:
$items = array('home' => 'ch41', 'page' => 'ch80', 'channel' => 'ch44', 'news' => 'ch42', 'contact' => 'ch83');
$page = (empty($_POST['choice']) ? 'home' : array_search($_POST['choice'], $items)); // Replace 'home' with whatever the default page is
// Then replace the <?= $key + 1 ?> below with just <?= $key ?>
?>
You are currently on page <?= $page ?>.
<form action="" method="post">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal" >
    <legend>เลือกช่อง</legend>
<?php foreach ($items as $key => $value): ?>
        <input type="radio" name="choice" id="radio-choice-<?= $key ?>" value="<?= $value ?>"<?= $key === $_POST['choice'] ? ' checked="checked"' : '' ?> />
        <label for="radio-choice-<?= $key ?>">number <?= $key + 1 ?></label>
<?php endforeach; ?>
</fieldset>
</div> 
</form>

一个粗略的例子。您可以向$items阵列添加其他频道。它将默认为第1页,并自动检查您当前正在查看的页面的单选按钮。我希望这就是你想要的。