文本区域不读取任何输入


Textarea not reading any input

文本区域未读取键入到框中的任何输入。最初,我使用 PHP 来检查文本区域是否为空,并且在那里收到错误。所以我删除了该检查,以查看是否是 php 导致了问题,并将 required="required" 属性添加到 textarea 标签中,即使它又回来了Please fill out this field.我不太确定我的代码哪里出了问题,我以前让它工作,然后突然它停止工作, 我完全不知道为什么。我还查看了有关文本区域未提交的其他各种帖子,并确保我正在用名称而不是 ID 检查帖子;并确保文本区域提交到与提交按钮相同的表单。我也尝试过它,但没有在文本区域标签上指定表单。

网页代码:

    <form action="" method="post" id="CreateTopicForm">
        <input type="hidden" name="create-topic" />
        <span class="secondary radius label"><strong>Title</strong></span>
        <input type="text" name="title" id="title" />
        <span class="secondary radius label"><strong>Message</strong></span>
        <textarea name="content" id="content" required="required" form="CreateTopicForm"></textarea>
        <?php if($_SESSION['user']['account_type'] >= 3): ?>
            <span class="secondary radius label"><strong>Sticky Topic</strong></span>
            <input type="checkbox" name="sticky" /><br />
        <?php endif ?>
        <input type="submit" value="Post Topic" class="topic-post" />
    </form>

PHP代码:

/* Retrieve necessary variables */
$fid = $_GET['fid'];
/* Get Forum Information */
$query = "SELECT * FROM bkg_forums where forum_id = :id";
$query_params = array(
':id' => $fid
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $e) {
$error[] = $pdoerror;
}
$forum = $stmt->fetchAll();
/* Begin the database upload */
if(!empty($_POST)){ /* Plan to change to if($_REQUEST['submit']) */
/* Check if data was actually submitted */

$db->beginTransaction();
/* DO SOME ERROR CHECKING. MAKE SURE FIELDS ARE NOT EMPTY. */
    if(empty($_POST['title'])){
        $error[] = "Sorry! You must enter a title!";
    }
    /* Previously had a check if $_POST['content'] */
/* GENERATE SOME VARIABLES NEEDED TO INSERT INTO TABLES. ACCOUNT_TYPE IS TEMPORARY*/
    if($_SESSION['user']['account_type'] == 0) {
        $account_type = "Normal";
        $color = "white";
    } elseif($_SESSION['user']['account_type'] == 1) {
        $account_type = "Donator";
        $color = "#F4FA58";
    } elseif($_SESSION['user']['account_type'] == 2) {
        $account_type = "Moderator";
        $color = "#2EFE2E";
    } elseif($_SESSION['user']['account_type'] == 3) {
        $account_type = "Community Manager";
        $color = "#0000FF";
    } elseif($_SESSION['user']['account_type'] == 4) {
        $account_type = "Administrator";
        $color = "#DF0101";
    }
    if(isset($_POST['sticky'])){
        $sticky = 1;
    } else {
        $sticky = 0;
    }



if(!isset($error)){

/* INSERT INTO TOPICS TABLE */
    $query = "INSERT INTO bkg_topics (
            forum_id,
            icon_id,
            topic_approved,
            topic_title,
            topic_text,
            topic_poster_id,
            topic_poster,
            topic_poster_color,
            topic_post_time,
            topic_status,
            topic_type
        ) VALUES (
            :forumid,
            :iconid,
            :topicapproved,
            :topictitle,
            :topictext,
            :topicposter_id,
            :topicposter,
            :topicposter_color,
            :topicpost_time,
            :topicstatus,
            :topictype
        )";
    $query_params = array(
        ':forumid' => $fid,
        ':iconid' => 1,
        ':topicapproved' => 1,
        ':topictitle' => $_POST['title'],
        ':topictext' => $_POST['content'],
        ':topicposter_id' => $_SESSION['user']['id'],
        ':topicposter' => $_SESSION['user']['displayname'],
        ':topicposter_color' => $color,
        ':topicpost_time' => time(),
        ':topicstatus' => 0,
        ':topictype' => $sticky
    );
    $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
        $lastid = $db->lastInsertId();
         /* Retrieve the last id of a topic, used to generate some links. */
        /* UPDATE FORUM TABLE */
    $query = "UPDATE bkg_forums SET
        `forum_last_post_id` = :lastpostid,
        `forum_last_post_topic_id` = :lastposttopicid,
        `forum_last_post_title` = :lastposttitle,
        `forum_last_poster_id` = :lastposterid,
        `forum_last_post_time` = :lastposttime,
        `forum_last_poster_name` = :lastpostername,
        `forum_last_poster_color` = :lastpostercolor
    WHERE `forum_id` = :forumid
    ";
    $query_params = array(
        ':lastpostid' => null,
        ':lastposttopicid' => $lastid,
        ':lastposttitle' => $_POST['title'],
        ':lastposterid' => $_SESSION['user']['id'],
        ':lastposttime' => time(),
        ':lastpostername' => $_SESSION['user']['displayname'],
        ':lastpostercolor' => $color,
        ':forumid' => $fid
    );
    $stmt = $db->prepare($query);
    $result = $stmt->execute($query_params);
    if($fid == 13){
        $query = "INSERT INTO updates (
            title,
            content,
            `date`,
            `user`,
            `topic_id`
        ) VALUES (
            :title,
            :content,
            :date_posted,
            :user_posted,
            :topic_id
        )";
        $query_params = array(
            ':title' => $_POST['title'],
            ':content' => $_POST['content'],
            ':date_posted' => time(),
            ':user_posted' => $_SESSION['user']['displayname'],
            ':topic_id' => $lastid
        );
        $stmt = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }

    try {
        $db->commit();
        $post_ok = 1;
    } catch(PDOException $e) {
        $erroradmin[] = $e->getMessage();
        $db->rollback();
    }
    if(isset($post_ok)): ?>
        <script>
            location.href = "http://www.boundlessknights.com?viewtopic&fid=<?php echo $fid; ?>&tid=<?php echo $lastid; ?>";
        </script>
    <?php else: ?>
        <?php $error[] = "Your topic did not post."; ?>
    <?php endif; ?>
    <?php 
}
}
?>

我看过的问题:

表单帖子未读取任何值

无法通过 post 方法获取文本区域的值

文本区域未使用表单发布

文本区域在 PHP 帖子中返回空值

TinyMCE不会始终保持底层textarea同步。 通常,当您发布表单时,TinyMCE会在发布表单之前更新textarea,但该过程似乎被必需的属性停止。 您可以使用以下 API 调用来强制 TinyMCE 更新文本区域:

tinymce.triggerSave();

这将强制TinyMCE在调用时更新textarea。您可以:

  • 在表单的提交事件中执行此操作
  • 在TinyMCE init中执行此操作:

    tinymce.init({
        selector: "textarea",
        setup: function (editor) {
            editor.on('change', function () {
                tinymce.triggerSave();
            });
        }
    });
    

您的页面正在使用TinyMCE编辑器。它在控制台中给出以下错误:An invalid form control with name='content' is not focusable.修复它将解决您的问题。

嗯,您是否尝试从文本区域中删除此"表单"属性?

<textarea name="content" id="content" required></textarea>

告诉我们当您尝试时它会做什么。

更改此内容

 <textarea name="content" id="content" required="required" form="CreateTopicForm"></textarea>

对此

  <textarea name="content" id="content" required="required" ></textarea>

您可能无法发布任何内容,因为您尚未指定表单的action属性。

<form action="" method="post" id="CreateTopicForm">

将其设置为php文件的名称(具有文件的正确路径(,它应该有效。

注意:要确保 $_POST 数组包含表单提交的值,请执行var_dump($_POST)