php 设置 HTML 表单 textarea 的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3318132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:19:50  来源:igfitidea点击:

Setting value of a HTML form textarea?

phphtml

提问by Skizit

I'm using the following to set the value of a text area..

我正在使用以下内容来设置文本区域的值..

<?php
$message = $_REQUEST['message'];
?>
<br/><b>Description</b><br/>
<TEXTAREA NAME="message" COLS=40 ROWS=6 value="<?=$message;?>"></TEXTAREA><br/><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />

but it doesn't appear to be working. The value of message is not null. Does anyone have any idea why it's not filling the value?

但它似乎不起作用。消息的值不为空。有谁知道为什么它没有填充价值?

回答by fabrik

Textarea has no value. You need to insert your message between the opening and closing tags.

文本区域没有价值。您需要在开始和结束标记之间插入您的消息。

<textarea><?php echo htmlspecialchars($message); ?></textarea>

回答by sshow

<textarea name="message" cols="40" rows="6"><?=$message?></textarea>

Note:Make sure $messageis properly sanitized and that short_open_tagis enabled. Otherwise, @fabric's accepted answer is a better answer.

注意:确保$message已正确消毒并short_open_tag已启用。否则,@fabric 接受的答案是更好的答案。

回答by Gihan Gamage

Also you can use this method...

你也可以用这个方法...

 `<textarea  rows="12" id="mytextarea"><?php echo $bio; ?> </textarea>

  <script>
  document.getElementById(`mytextarea`).innerHTML="Include the text you want to display";
  </script>`