【问题标题】:Textarea PHP post issueTextarea PHP发布问题
【发布时间】:2014-06-18 20:09:17
【问题描述】:

我有一个文本区域的 PHP 发布问题。我已经搜索了这个站点,建议的补救措施包括提取 textarea 的 ID,并确保您使用的是 htmlspecialchars。我都在做,但我仍然无法弄清楚为什么它不会发布我的 textarea 的内容。

HTML

<form method="post" action="email.php" name="contactform" id="contactform" class="form form-stacked c-form">
<input name="name" type="text" id="name" placeholder="Name" />
<input name="email" type="text" id="email" placeholder="E-mail" />
<textarea name="theTextArea" placeholder="Message"></textarea>
<input type="submit" class="submit btn outline" id="submit" value="Send message" />
</form>

PHP

$realName = $name = $theMessage = $subject = $WHATmessage = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $realName = test_input($_POST["name"]);
  $name = test_input($_POST["email"]);
  $theMessage = test_input($_POST["theTextArea"]);
}
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}

$subject = 'SUPERGROUP Inquiry - ' . $realName . ' - [' .date("F j, Y, g:i a").']';
$WHATmessage = $realName . ' is looking forward to hearing from us!'.PHP_EOL.'Their email is: '. $name .'!'.PHP_EOL.'They said: "'.$theMessage.'"';
mail('hello@sprgrp.com', $subject, $WHATmessage ); 

【问题讨论】:

  • 什么是“test_input”?如果你在寻找价值,你就没有得到它。你得到了“test_input”的结果。
  • test_input 只是通过 htmlspecialchars 运行数据。
  • 啊。所以“test_input”是一个返回清理后的字符串的函数。这就说得通了。那么,你从中得到什么?或者,你试过没有那个吗?
  • 我试过没有它,但我仍然一无所获。 var_dump($theMessage) 只产生我在开头设置的空白字符串。
  • 你试过用单引号而不是双引号吗? PHP 可能对此很有趣。

标签: php html post textarea


【解决方案1】:

发表评论作为答案,因为它似乎有效。

您是否尝试过所有这些都用单引号而不是双引号? PHP 可能对此很有趣。

【讨论】:

    【解决方案2】:

    这里有几件事......

    “名称”是保留字。不要使用 name 作为你的名字。

     <input name="name"
    

    这可能是您大多数发帖问题的核心问题。

    相反,试试

    <input name="fullname"
    

    此外,您希望在 POST 上“添加斜杠”,而不是“带斜杠”。您在 db 查询后删除以将“原始”源显示给用户。 不过,这主要用于数据库交互。 对于电子邮件,基本上没有必要这样做。 htmlspecialchars 应该处理其他所有事情。

    【讨论】:

    • 我已经知道这个名字了。这个名字有效。我会试试addlashes,看看它是否有效,谢谢!
    • 我将名称更改为“全名”,反映了 PHP 中的更改,现在我也没有得到。
    • 您可能想在您的字段上尝试单引号,$_POST['myfield']
    猜你喜欢
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-10
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    相关资源
    最近更新 更多