Hey. I'm a true novice. Web designer by day, i'm doing a website for myself now (finally) which means i've turned developer overnight and i'm way out of my comfort zone.
It's a very simple contact form - here's the code:
<?php
$myemail = "";
$subject = "Website Enquiry";
$yourname = check_input($POST['yourname']);
$email = check_input($POST['email'],"Enter your Email address");
$phone = check_input($POST['phone']);
$howcontact = check_input($POST['howcontact']);
$enquiry = check_input($_POST['enquiry']);
if (!preg_match("/([\w-]+@[\w-]+.[\w-]+)/", $email))
{
show_error("Email address not valid");
}
$message = "New Enquiry:
Name: $yourname
Email Address: $email
Phone Number: $phone
Contact By: $howcontact
Enquiry:
$enquiry
";
mail($myemail, $subject, $message);
header('Location: thanks.html');
exit();
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
<a href="/fripperies_contact.html">back to contact form</a>
</body>
</html>
<?php
exit();
}
?>
This works, but it doesn't work exactly how i'd like it to since it's essentially a cobbled together first attempt. Currently if there's an error you're directed to a new page. Instead, I'd like the error to be highlighted in the form page, with the other fields retaining the text already input. I searched until the wee small hours of the morning for some answers, and found nothing I could get my head around. If someone doesn't mind helping me out i'd be so grateful! Thankyou!!!