如何保持 html
假设我有一个这样的表单:
<form action="page.php" method="post">
Section1: <input name="section1" type="text"></br>
Section2: <input name="section2" type="text"></br>
Text:</br>
<textarea name="post_text" cols="100" rows="20"></textarea>
<input name="submit" type="submit" value="Submit">
</form>
通常如果我希望保存插入表单字段中的内容,我会使用以下语句:
Section1: <input name="section1" type="text" vale="value="<?php echo $_POST['section1']; ?>""></br>
这样,如果我在提交时犯了错误(未发布错误控制代码),则插入的值将是保留,无需重新插入。
但是,在 textarea 标记中使用它不会产生所需的结果。
关于如何做有什么想法吗?
提前致谢!
Suppose I have a form like this:
<form action="page.php" method="post">
Section1: <input name="section1" type="text"></br>
Section2: <input name="section2" type="text"></br>
Text:</br>
<textarea name="post_text" cols="100" rows="20"></textarea>
<input name="submit" type="submit" value="Submit">
</form>
Usually if I wish to save content inserted in a field of the form I would use this statement:
Section1: <input name="section1" type="text" vale="value="<?php echo $_POST['section1']; ?>""></br>
This way if I make a mistake in submission (error control code is not posted) the values inserted will be kept, and there is no need to reinsert them.
However using it in the textarea tag it will not produce the desired result.
Any ideas on how to do?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不要忘记 htmlspecialchars()。这应该有帮助: https://developer.mozilla.org/en/HTML/Element/textarea
Don't forget about htmlspecialchars(). This should help: https://developer.mozilla.org/en/HTML/Element/textarea
您可以使用相同的方法,但将
echo
放在开始和结束标记之间,作为
textarea
没有“值”(因此)它有文本内容:You could use the same approach, but put the
echo
between the opening and closing<textarea></textarea>
tags, as thetextarea
doesn't have a 'value' (as such) it has textual content:像这样使用
$_POST
变量。内联条件检查是否设置了
$_POST['post_text']
以删除 NOTICE 警告Use the
$_POST
variable like this.the inline conditional checks if the
$_POST['post_text']
is set to remove the NOTICE warning您可以将其放入
但是,直接调用 $_POST 元素并不是最佳实践。您应该这样做:
这会阻止在第一次页面加载时报告 E_NOTICE 错误。
You would put it inside the
<textarea>
element like so:However, calling the $_POST element directly is not best practice. You should rather do something like this:
This stops an E_NOTICE error from being reported upon the first page-load.