如何将文本插入到 html <textarea>提交错误后? [英] How to keep text inserted in a html <textarea> after a wrong submission?

查看:26
本文介绍了如何将文本插入到 html <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.

但是在 textarea 标签中使用它不会产生预期的结果.

However using it in the textarea tag it will not produce the desired result.

关于如何做的任何想法?

Any ideas on how to do?

提前致谢!

推荐答案

不要忘记 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

<textarea name="post_text" cols="100" rows="20"><?php echo htmlspecialchars($_POST['post_text']);?></textarea>

这篇关于如何将文本插入到 html &lt;textarea&gt;提交错误后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆