Reputation: 29
I have a contact form which send a email with the fields that are filled in. Only if the fields are empty than there is a error message that there are fields missing. The problem is that the errormessage doesn't show on the page.
This is my php page.
<?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('[email protected]', 'Contact Form', $body, 'From: [email protected]');
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");
}
}
?>
On the redirected page I use a $_GET function to call the querystring.
<?php print $_GET["errormessage"];?>
What am I doing wrong because tthe errormessage isn't shown.
Upvotes: 0
Views: 67
Reputation: 578
Where you are writing <?php print $_GET["errormessage"];?>
as i can see you are redirecting threw header to "contact.html" with below code header( "Location: contact.html?errormessage=$errormessage");
On html page we can not use php $_GET["errormessage"]
Upvotes: 1
Reputation: 9351
You can't get $_GET
in html page.
You need php page to do that.
create contact.php instead of contact.html.
and try this:
header( "Location: contact.php?errormessage=$errormessage");
Upvotes: 0