【问题标题】:Show errormessage when contact form fails联系表单失败时显示错误消息
【发布时间】:2014-03-13 08:58:47
【问题描述】:

我有一个联系表格,它会发送一封电子邮件,其中包含已填写的字段。仅当字段为空时,才会显示缺少字段的错误消息。问题是错误消息没有显示在页面上。

这是我的 php 页面。

<?php
if (isset($_POST['submit'])) {
$body = '';

$body .= 'Naam: ' . $_POST['naam'] . "\n";
$body .= 'Telefoon: ' . $_POST['telefoon'] . "\n";
$body .= 'Email: ' . $_POST['email'] . "\n";
$body .= 'Bericht: ' . $_POST['bericht'] . "\n";
$body .= 'Adres: ' . $_POST['adres'] . "\n";

if (($_POST['naam'] &&  $_POST['email'] &&  $_POST['bericht'] && $_POST['telefoon'] !=""))
{
mail('someone@mail.com', 'Contact Form', $body, 'From:     no-reply@mycompany.com');
header( "Location: /bedankt.html");
}
else
{
$naamErr = $berichtErr = $emailErr = $telefoonErr = $errormessage = "";
$errormessage = "De volgende velden waren niet ingevuld: ";
if($_POST['naam'] == "")
{
$errormessage .= "naam,";
}
if($_POST['bericht'] == "")
{
$errormessage .= "bericht,";
}
if($_POST['email'] == "")
{
$errormessage .= "email,";
}
if($_POST['telefoon'] == "")
{
$errormessage .= "telefoon";
}

header( "Location: contact.html?errormessage=$errormessage");
}
}


?>

在重定向页面上,我使用 $_GET 函数调用查询字符串。

<?php print $_GET["errormessage"];?>

我做错了什么,因为没有显示错误消息。

【问题讨论】:

  • 定义'不起作用'
  • 不显示错误信息
  • 在contact.html页面,怎么能使用php打印功能????
  • 将contact.html改为contact.php,然后使用php打印功能就可以了。
  • 忘记 $_GET。你甚至看到地址栏中的值吗?

标签: php html mail-form


【解决方案1】:

您在哪里写&lt;?php print $_GET["errormessage"];?&gt;,我可以看到您正在使用以下代码将投掷标头重定向到“contact.html”header( "Location: contact.html?errormessage=$errormessage");

在 html 页面上我们不能使用 php $_GET["errormessage"]

【讨论】:

    【解决方案2】:

    您无法在 html 页面中获取$_GET

    你需要 php 页面来做到这一点。

    创建contact.php而不是contact.html。

    试试这个:

    header( "Location: contact.php?errormessage=$errormessage");
    

    【讨论】:

      猜你喜欢
      • 2015-04-17
      • 2014-12-19
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 2017-04-26
      • 1970-01-01
      相关资源
      最近更新 更多