我正在尝试用PHP制作一个表格,以便将文章发布到新闻页面。目标是用Markdown编写这些文章,将它们存储在数据库中,并在显示之前使用Parsedown解析它们。
我的一个想法是添加一个预览按钮,将表单发布到自己的页面,以便在发布之前显示已解析的文本(因为用户不是定期使用Markdown的人,这样她就可以在发送之前检查错误)。此外,当单击按钮时,我不希望字段的内容消失,所以我希望将POST值插入其中。不过,这不管用。
<div class="presentation">
<form id="actuform" action="" style="text-align: center;">
<label for="title">Title</label>
<br>
<input type="text" name="title" id="title" placeholder="Title" value=<?php echo '"'.$_POST['title'].'"'; ?> required>
<br>
<label for="content">Body</label>
<br>
<textarea class="actusub" name="content" id="content" placeholder="Body" style="width: 100%; max-width: 80%; min-height: 350px; resize: none;" required><?php echo $_POST['content']?></textarea>
<br>
<button type="button" onclick="handleSubmit(0)">Post</button>
<button type="button" onclick="handleSubmit(1)">Preview</button>
</form>
<script>
form = document.getElementById("actuform");
function handleSubmit(choice) {
if(choice==0){
form.action="actu_post.php"; // publish
} else {
form.action=""; // preview
};
form.submit();
}
</script>
<div"> <!--Markdown preview-->
<?php
$Parsedown = new Parsedown();
$Parsedown->setSafeMode(true);
echo $Parsedown->text($_POST['content']);
?>
</div>
</div>当我运行这个URL时,URL会显示POST值,但是字段是空的,预览也不会出现。我不知道该如何调试它。我有什么明显的遗漏吗?
发布于 2021-06-01 13:39:11
您必须指定表单正在执行POST请求,如果没有,默认情况下会发出GET请求。
<form method="POST" id="actuform" action="" style="text-align: center;">https://stackoverflow.com/questions/67789877
复制相似问题