0

我这里有一个下拉菜单:

        $pHTML = "";

             $moduledrop = isset($_POST['modules']) ? $_POST['modules'] : '';

                    $moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL;
                 $moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;  
                ....
                $moduleHTML .= '</select>'; 

....

    <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
    <table>
    <tr>
    <th>Module: <?php echo $moduleHTML; ?></th>
    </tr>
    </table>
    <p><input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /></p>
    </form>

我的问题很简单,如果用户选择Please Select下拉菜单并提交,它应该显示Please Select a Module消息。但它没有显示此消息。为了做到这一点,我需要在下面的代码中进行哪些更改:

     if (isset($_POST['moduleSubmit']) || isset($_POST['sessionSubmit'])){  

         if($_POST['modules'] == ''){
            $pHTML = "<span style='color: red'>Please Select a Module</span>";
            }else if($sqlnum == 0){
            $pHTML = "<span style='color: red'>Sorry, You have No Assessments under this Module</span>";
            } else{
            $pHTML = "<span style='color: green'>Assessment Successfully Found</span>";

                $assessmentform = "<div id='lt-container'>
                <form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
                <p id='warnings'>{$pHTML}</p>
  <p><input id="sessionSubmit" type="submit" value="Submit Assessment" name="sessionSubmit" /></p>
                </form>
                </div>";

                echo $assessmentform;

                }

            }
4

1 回答 1

0

我不确定您的整个脚本到底是什么样子,并且很难判断代码在您的示例中属于哪里,但我猜$moduledrop = isset($_POST['modules']) ? $_POST['modules'] : '';是导致问题的原因。

您需要将所有代码一起发布。很难看出什么去了哪里。我只看到两个表单和两个地方检查代码是否已提交。我只是把这些放在一起,让你知道你需要做什么。下面的代码有效。如果您仍然需要帮助,请张贴整个页面,以便我知道我在读什么。

尝试:

<?php

$pHTML = "";
$moduledrop = isset($_POST['modules']) ? $_POST['modules'] : '';
$moduleHTML .= '<select name="modules" id="modulesDrop">' . PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>' . PHP_EOL;
$moduleHTML .= '</select>';

if (!empty($_POST)) {

    if ($_POST['modules'] == '') {
        $pHTML = "<span style='color: red'>Please Select a Module</span>";
    } else if ($sqlnum == 0) {
        $pHTML = "<span style='color: red'>Sorry, You have No Assessments under this Module</span>";
    } else {
        $pHTML = "<span style='color: green'>Assessment Successfully Found</span>";
    }
    echo $pHTML;
}

?>

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table>
    <tr>
        <th>Module: <?php echo $moduleHTML; ?></th>
    </tr>
</table>
<p>
    <input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
</p>
</form>
于 2013-01-13T20:04:53.020 回答