我正在尝试处理表格。如果有错误,用户将被重定向到表单,错误将在此处显示,用户尝试提交的任何内容都会在表单的 tinymce 的 textarea 中回显。这样,用户就不必再次重写所有内容。一切都运行良好,除了用户被重定向后会话变量不会在 tinymce 编辑器中回显。会话变量已设置并具有正确的值。如果我在 tinymce 之外回显会话变量,它会按预期显示。它只是不会出现在文本区域中。我该如何解决?
另外,我知道这很容易受到 xss 的影响。我想让用户格式化他们的帖子,所以稍后我将通过 HTML Purifier 运行它。
添加新线程.php:
<?php
session_start();
if($_SERVER['REQUEST_METHOD']==='POST')
{
if(isset($_POST['submit'])&&$_POST['submit']==='success')
{
if (empty(trim($_POST['thread-title'])))
{
$_SESSION['forum_titErr'] = "<p class='error text-center'>Error message</p>";
}
else
{
$_SESSION['threadTitle'] = $_POST['thread-title'];
}
if (empty(trim($_POST['thread-content'])))
{
$_SESSION['forum_thrContErr'] = "<p class='error text-center'>Error message </p>";
}
else
{
$_SESSION['threadCont'] = $_POST['thread-content'];
}
if((isset($_SESSION['forum_titErr'])&&!empty($_SESSION['forum_titErr']))|| (isset($_SESSION['forum_thrContErr'])&&!empty($_SESSION['forum_thrContErr'])))
{
header("Location: newthread.php?submit=error");
}
else
{
//insert into database and redirect to readtopic.php if insert is successful; else redirect to form and show insert is not successful
}
}
else{
header("Location: newthread.php");
}
}
else
{
exit('invalid request');
}
?>
表单html:
<!DOCTYPE html>
<html>
<?php
session_start();
?>
<head>
<!-- title, meta, stylesheet, etc. -->
<script type="text/javascript" src="jquery.js"></script>
<script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>
<script>tinymce.init({selector:"#threadCont", height: 300, resize: false
});</script>
</head>
繁星点点滴滴
拉风的咖菲猫
侃侃尔雅