两个动作表单和两个提交按钮,如何保留值?

Two action forms and two submit buttons, how to keep the values?

我在页面中有 2 个操作表单和 2 个提交按钮。

1 是缩放级别

1 是以秒为单位的刷新率

当我点击缩放提交时,刷新率被重置 当我点击提交刷新率时,缩放级别被重置

当一个下拉菜单设置为特定值时,如何保持另一个的值?

我认为这是菜鸟遇到的一个常见问题,所以如果能在这里得到专家的一些很好的解释和很好的指导会很好...

代码是:

<?php
        $submittedValue = "";
        $value0 = 1;
        $value1 = 1.2;
        $value2 = 1.5;
        $value3 = 2;
        if (isset($_POST["FruitList"])) {
            $submittedValue = $_POST["FruitList"];
        }
        ?>
        <form action="example3b2vandaag.php" name="fruits" method="post">
        <select project="FruitList" id="FruitList" name="FruitList">
         <option value = "<?php echo $value0; ?>"<?php echo ($value0 == $submittedValue)?" SELECTED":""?>><?php echo "off"; ?></option>
         <option value = "<?php echo $value1; ?>"<?php echo ($value1 == $submittedValue)?" SELECTED":""?>><?php echo $value1; ?></option>
         <option value = "<?php echo $value2; ?>"<?php echo ($value2 == $submittedValue)?" SELECTED":""?>><?php echo $value2; ?></option>
         <option value = "<?php echo $value3; ?>"<?php echo ($value3 == $submittedValue)?" SELECTED":""?>><?php echo $value3; ?></option>
        </select>
        <input type="submit" name="submit" id="submit" value="Set zoom level" />
        </form>






        <?php
        $submittedValue = "";
        $value0 = 1000;
        $value1 = 20000;
        $value2 = 30000;
        $value3 = 90000;
        if (isset($_POST["FruitList2"])) {
            $submittedValue = $_POST["FruitList2"];
        }
        ?>
         <form action="example3b2vandaag.php" name="fruits2" method="post">
        <select project="FruitList2" id="FruitList2" name="FruitList2">
         <option value = "<?php echo $value0; ?>"<?php echo ($value0 == $submittedValue)?" SELECTED":""?>><?php echo $value0; ?></option>
         <option value = "<?php echo $value1; ?>"<?php echo ($value1 == $submittedValue)?" SELECTED":""?>><?php echo $value1; ?></option>
         <option value = "<?php echo $value2; ?>"<?php echo ($value2 == $submittedValue)?" SELECTED":""?>><?php echo $value2; ?></option>
         <option value = "<?php echo $value3; ?>"<?php echo ($value3 == $submittedValue)?" SELECTED":""?>><?php echo $value3; ?></option>
        </select>
        <input type="submit" name="submit" id="submit" value="Set refresh milliseconds" />
        </form>

我看不出有任何理由需要两种形式,您可以将两个 select 框放在一种形式中。 并且请不要使用不智能的变量名称,例如 $value0、$submittedValue 和 $Fruitlist,因为这与水果无关。

这里把两个select盒子合为一个形式:

<?php

    $zoom = "";
    $zoom0 = 1;
    $zoom1 = 1.2;
    $zoom2 = 1.5;
    $zoom3 = 2;
    $refresh = "";
    $refresh0 = 1000;
    $refresh1 = 20000;
    $refresh2 = 30000;
    $refresh3 = 90000;

    if (isset($_POST["zoom"])) {
        $zoom = $_POST["zoom"];
    }
    if (isset($_POST["refresh"])) {
        $refresh = $_POST["refresh"];
    }
    ?>
    <form action="testForm.php" name="controlpanel" method="post">
    ZoomLevel:<br />
    <select project="ControlPanel" id="ControlPanel" name="zoom">
     <option value = "<?php echo $zoom0; ?>"<?php echo ($zoom0 == $zoom)?" SELECTED":""?>><?php echo "off"; ?></option>
     <option value = "<?php echo $zoom1; ?>"<?php echo ($zoom1 == $zoom)?" SELECTED":""?>><?php echo $zoom1; ?></option>
     <option value = "<?php echo $zoom2; ?>"<?php echo ($zoom2 == $zoom)?" SELECTED":""?>><?php echo $zoom2; ?></option>
     <option value = "<?php echo $zoom3; ?>"<?php echo ($zoom3 == $zoom)?" SELECTED":""?>><?php echo $zoom3; ?></option>
    </select>
    <br />
    Refresh rate:<br />
    <select project="ControlPanel" id="ControlPanel" name="refresh">
     <option value = "<?php echo $refresh0; ?>"<?php echo ($refresh0 == $refresh)?" SELECTED":""?>><?php echo $refresh0; ?></option>
     <option value = "<?php echo $refresh1; ?>"<?php echo ($refresh1 == $refresh)?" SELECTED":""?>><?php echo $refresh1; ?></option>
     <option value = "<?php echo $refresh2; ?>"<?php echo ($refresh2 == $refresh)?" SELECTED":""?>><?php echo $refresh2; ?></option>
     <option value = "<?php echo $refresh3; ?>"<?php echo ($refresh3 == $refresh)?" SELECTED":""?>><?php echo $refresh3; ?></option>
    </select><br />

    <input type="submit" name="submit" id="submit" value="Set configurations" />
    </form>

要使用从表单中获取的数据,您可以使用 $_POST["zoom"] 和 $_POST["refresh"],因为那是 select 的名称属性盒子是。 有关 html 表单以及如何使用 $_POST 数据的更多信息,请参阅 http://www.w3schools.com/php/php_form_complete.asp