Hi!
I'm almost satisfied with this mail validation. However, I need some help to get it all fixed. 🙂
How may I get the error text
die("<h2>Sorry, there is $errcount faults in your form. Please correct these faults:</h2>" . $error);
to be dislayed in my already established html-page error.htm (or perhaps I'll have to rename it error.php if I'll need some php-code to it..).
Here is my code:
<?php
if($_POST['submit'])
$errcount = 0;
$error = '';
{ //check to see if someone has filled out a form
//Validates the name
if(preg_match('/^[a-zæøåÆØÅ_-]{2,}$/i', $_POST['navn'])){
$navn = $_POST['navn'];
} else {
$error .= "You didn't write a name!<br />";
$errcount++;
}
{ //Validates the lastname
if(preg_match('/^[a-zæøåÆØÅ_-]{2,}$/i', $_POST['etternavn'])){
$etternavn = $_POST['etternavn'];
} else {
$error .= "You didn't write a lastname!<br />";
$errcount++;
}
//validates telephonenumber
if(preg_match('/^[0-9_-]{8,}$/i', $_POST['mobil'])){
$mobil = $_POST['mobil'];
} else {
$error .= "You didn't write a telephonenumber!<br />";
$errcount++;
}
//Validate emailaddress
if(preg_match('/^[\w]+[-\w._]*@[\w]+[-\w]+(\.[\w]+[-\w]+)*\.[\w]{2,6}$/ ', $_POST['email'])){
$epost = $_POST['email'];
} else {
$error .= "You didn't write a correct email address!<br />";
$errcount++;
}
if (empty($_POST['melding'])) {
$error .= "You didn't write a message!<br />";
$errcount++;;
} else {
$_POST['melding'];
}
//Check if some errors are found
//if so, stop the script and display the following
if($errcount !=0){
die("<h2>Sorry, there is $errcount faults in your form. Please correct these faults:</h2>" . $error);
}
else {
$emne = $_POST['emne'];
$mailheaders = "From: " .$navn ." " .$etternavn ." <". $epost . ">\n";
$mailheaders .= "Reply-To: <". $epost . ">\n";
$to = 'my@domain.no';
$melding = $_POST['melding'];
$melding = "Fra: $navn $etternavn\nTelefon: $mobil\n\nMelding:\n$melding";
mail( $to, $emne, $melding, $mailheaders, '-fmail@domain.no'); //Send Mail
{
header ("Location: http://www.domain.no/thankyou.htm" );
}
}
}
}
?>
Anyone, please..:-) ?