在我的表单中显示输出的数据,以便我可以编辑
我如何显示输出的数据(contents.html)进入我的表单文本区域(edit.html)。我在表单页面中使用了 JS HTML WYSIWYG 编辑器(TinyMCE),以便没有 HTML 经验的人可以更轻松地进行编辑。
(我知道 XSS 攻击,但我现在只想让它发挥作用。) 我尝试过 echo 但它不起作用,有人知道我如何实现这一目标吗?
问候
edit.php // 将表单数据提交到contents.html
<?php file_put_contents("content.html", print_r($_POST['content'], true)); ?>
<form method="post">
<textarea name="content" style="width:960px; margin: 0 auto;" rows="20" cols="20">
</textarea>
<input type="submit" name="save" value="Submit" />
</form>
contents.html
// 空白,直到与表单一起提交内容
index.php< /strong>
// 从contents.html 中检索数据并显示
<?php echo file_get_contents('content.html');?>
How can i display the outputted data that is (contents.html) to go in my form textarea (edit.html). I am using a JS HTML WYSIWYG editor (TinyMCE) in the form page to make it easier for people with no HTML experience to make edits.
(i am aware of XSS attacks but i'd just like to get this working for now.)
I have tried echo but it will not work, anyone know how i can achieve this?
Regards
edit.php
// Submits form data to contents.html
<?php file_put_contents("content.html", print_r($_POST['content'], true)); ?>
<form method="post">
<textarea name="content" style="width:960px; margin: 0 auto;" rows="20" cols="20">
</textarea>
<input type="submit" name="save" value="Submit" />
</form>
contents.html
// Blank until something is submitted with the form
index.php
// Retrieves data from contents.html and displays it
<?php echo file_get_contents('content.html');?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在转义文本区域后打印文本区域中的内容即可。这将防止您的表单 (edit.php) 中出现 XSS,并导致 HTML 内容正确显示。
if 语句检查表单是否已提交。如果是这样,
$_POST['content']
中的内容将被写入content.html
。注意:isset($_POST['save'])
和name="save"
是可选的,用于检查表单是否已提交,但如果您已提交多个提交选项(例如,预览按钮),这是必需的。Just print the contents in the textarea, after escaping it. This will prevent XSS in your form (edit.php), and cause the HTML contents to be shown correctly.
The if-statement checks whether the form has been submitted or not. If that's true, the contents from
$_POST['content']
will be written tocontent.html
. Note:isset($_POST['save'])
andname="save"
are optional for checking whether the form has been submitted or not, but if you've multiple submit options (e.g., a preview button), it's required.