尝试使用 PHP 和 JS 向自己提交 HTML 表单,但无法正常工作

Trying to submit a HTML form to itself using PHP and JS and it's not working

我正在尝试使用 PHP 创建一个用于将文章发布到新闻页面的表单。目的是将这些文章用Markdown写好,存入数据库,用Parsedown解析后再展示。

我的一个想法是添加一个预览按钮,该按钮 POST 将表单添加到它自己的页面以在发布之前显示已解析的文本(因为用户不是经常使用 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 显示 POST 值,但字段为空白且不显示预览。我不确定我应该如何调试它。有什么明显的我想念的吗?

您必须指定表单正在执行 POST 请求,否则默认会发出 GET 请求。

<form method="POST" id="actuform" action="" style="text-align: center;">