麻烦在AED标签中嵌入php

时间:2014-01-28 18:36:37

标签: php html

我正在尝试将下拉列表中的值分配给变量,如下所示:

<?php



$submittedValue = "";
$value0 = " ";
$value1 = "mr";
$value2 = "ms";
$value3 = "mrs";
if (isset($_POST["salute"])) {
    $submittedValue = $_POST["salute"];
}


$html =null;



//form with data
$html .= "

        <form action='' name='salute' method='post'>
        <select project='salute' id='salute' name='Salute'>
         <option value = '<?php echo $value0; ?>'<?php echo ($value0 == $submittedValue)?' SELECTED':''?>><?php echo $value0; ?></option>
         <option value = '<?php echo $value1; ?>'<?php echo ($value0 == $submittedValue)?' SELECTED':''?>><?php echo $value1; ?></option>
         <option value = '<?php echo $value2; ?>'<?php echo ($value0 == $submittedValue)?' SELECTED':''?>><?php echo $value2; ?></option>
         <option value = '<?php echo $value3; ?>'<?php echo ($value0 == $submittedValue)?' SELECTED':''?>><?php echo $value3; ?></option>
        </select>
        </form>

        ";
?>  

我想稍后访问,如下所示:

$test['main'] = <<<EOD


{$html}


EOD;

但是,我错误地嵌入了它,我知道第一部分不应该像$ html变量那样编写。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

修改

快速记录。您的name='Salute'大写S应该是name='salute' - 这会导致与$_POST["salute"]

一起出错
<?php
$submittedValue = "";
$value0 = " ";
$value1 = "mr";
$value2 = "ms";
$value3 = "mrs";
if (isset($_POST["salute"])) {
    $submittedValue = $_POST["salute"];

}

$html =null;

//form with data
$html .= "

        <form action='' name='salute' method='post'>
        <select project='salute' id='salute' name='salute'>
         <option value = ' $value0 ' ($value0 == $submittedValue)?' SELECTED':''>$value0</option>
         <option value = ' $value1 ' ($value1 == $submittedValue)?' SELECTED':''>$value1</option>
         <option value = ' $value2 ' ($value2 == $submittedValue)?' SELECTED':''>$value2</option>
         <option value = ' $value3 ' ($value3 == $submittedValue)?' SELECTED':''>$value3</option>
        </select>

<input type='submit' name='submit' value='Submit'>

        </form>

        ";

echo $test['main'] = <<<EOD

{$html}

$submittedValue

EOD;

试一试。它确实回显了下拉菜单,但我不确定这是否是与您现有的三元运营商合作的理想结果。

如果不是,我可以删除它,或者你可以修改它。

<?php
$submittedValue = "";
$value0 = " ";
$value1 = "mr";
$value2 = "ms";
$value3 = "mrs";
if (isset($_POST["salute"])) {
    $submittedValue = $_POST["salute"];
}


$html =null;

//form with data
$html .= "

        <form action='' name='salute' method='post'>
        <select project='salute' id='salute' name='Salute'>
         <option value = '$value0'($value0 == $submittedValue)?' SELECTED':''>$value0</option>
         <option value = '$value1'($value0 == $submittedValue)?' SELECTED':''>$value1</option>
         <option value = '$value2'($value0 == $submittedValue)?' SELECTED':''>$value2</option>
         <option value = '$value3'($value0 == $submittedValue)?' SELECTED':''>$value3</option>
        </select>
        </form>

        ";

echo $test['main'] = <<<EOD
<h1>{$test['title']}</h1>

{$html}

EOD;

答案 1 :(得分:0)

首先     <option value = '<?php echo $value0; ?>' 应为<option value='$value0'

现在我看到的问题是<h1>{$test['title']}</h1>

在EOD之前尝试$title = $test['title']

$test['main'] = <<< EOD
<h1>$title</h1>

{$html}

EOD;