将文本复制粘贴到文本区域会返回空白结果吗?

时间:2016-06-12 14:36:54

标签: php html mysql

我有一个提交到数据库的表单,然后这些提交被回显到页面上。当我在textarea中输入文本时,一切都很好。但是,如果我将粘贴复制到文本区域,文本就会很好地输入到数据库中,但它会回显空白。

这是我的表格:

        <form method="post" action="post.php" id="messageForm" autocomplete="off">
            <table border="0" align="center">
                <tr><td id="formBlock" style><span>Name</span></td>
                <td><input id="messageName" name="name" type="text" value="Anonymous" maxlength="32" required>
                    <input style="margin-right: -1px; margin-left: -4px;" type="submit" name="Submit" value="Send Message"></td></tr>
                <tr><td id="formBlock"><span>Title</span></td>
                    <td><input id="messageTitle" name="title" type="text" maxlength="32" width="20"></td></tr><br>
                <tr><td id="formBlock"><span>Message</span></td>
                    <td><textarea onkeyup="countChar(this)" name="message" rows="6" cols="50" form="messageForm" maxlength="2000" style="font-family: arial;" required></textarea></td></tr>
                <tr> <td id="formBlock"><span>Tags</span></td>
                    <td><input id="messageTags" name="tags" type="text" maxlength="64" width="100" placeholder="separated by commas: cats, anime, zelda, etc"></td></tr>
            </table>
        </form>

以下是它的回应:

            if ($result->num_rows > 0) {
                while($row = $result->fetch_assoc()) {
                    echo "<br><div id='messageBar'><b><a class='rateup' href='javascript:;' data-id=' " . $row['id'] . " ' title='vote up'>&#9650;</a> ";
                    echo $row["rating"];
                    echo " <a class='ratedown' href='index.php' title='vote down'>&#9660;</a> </b>";
                    echo "Posted by <b>";
                    echo htmlspecialchars($row["name"], ENT_QUOTES, 'UTF-8');
                    echo "</b> on ";
                    echo $row["date"];
                    echo " at ";
                    echo $row["time"];
                    if (!empty($row['title'])) {
                        echo " - <b>";
                        echo htmlspecialchars($row["title"], ENT_QUOTES, 'UTF-8');
                        echo "</b>";
                    }
                    echo "<span style='float: right'>#";
                    echo $row["id"];
                    echo "</span>";
                    echo "</div><div id='messageContent'>";
                    echo htmlspecialchars($row["message"], ENT_QUOTES, 'UTF-8');
                    echo "<br><br><span id='commentLink'><a class='noStyle' href=''>reply to this post&nbsp;</a></span>";
                    echo "<br></div><br><hr>";
                }
            } else {
                echo "<br>";
                echo "<center><i>it's dusty in here</i></center>";
                echo "<br>";
            }

我真的不知道为什么会这样,我以前从未见过这样的事情。

编辑:

新开发,我删除了htmlspecialchars并且它工作正常,但是我不能禁用它,因为人们可以将代码放入消息中。什么是解决方法?

0 个答案:

没有答案