PHP将<option>数据加载到<textarea> </textarea> </option>

时间:2011-03-06 13:08:30

标签: php

<select name="template" id="template">
        <option value="none">Don't use template</option>
        <option value="RWT">Report Abuse</option>
        <option value="renew">Resend Email Codes</option>
    </select><br/>
    <textarea name="body" rows="10" id="content" value="<?php echo $body;?>"ondblclick="select_all('content');" cols="40"></textarea><br/>

...

else if ($template == "renew") {
        $body = "Dear $username,<br/></br/>";
        $body .= "Here is your requested activation code: $activationID <br/><br/>";
        $body .= "Thank you.<br/>";
    }

当我选择“续订”选项时,它不会将数据加载到我的textarea中。如何在textarea中加载选项数据?

3 个答案:

答案 0 :(得分:5)

必须进入textarea标记:

<textarea name="body" rows="10" id="content" ondblclick="select_all('content');" cols="40">
  <?php echo $body;?>
</textarea>

更新:正如评论中提到的那样,echo htmlspecialchars($body)会更好,因为这是正确的做事方式 - 在这种特定情况下,没有区别,但其他时间除非您这样做,否则您的应用程序将容易受到XSS攻击。

答案 1 :(得分:1)

您没有设置textarea的值 - 只需在一对textarea元素中插入所需的内容即可。例如:

<textarea name="body" id="content" ondblclick="select_all('content');" rows="10" cols="40">
<?php echo $body; ?>
</textarea>

答案 2 :(得分:0)

尝试将模板和正文变量回显到您的页面以进行调试。他们的价值观是什么?