Hi all, This is my very first post here 🙂
I am kinda newbie in php.
I have got a html contact us form designed in html and a contactinfo.php page that checks for ur input from the form and checks for any errors. It is working fine but i have got some validation issue.
here is the html form:
<form action="contactinfo.php" method="post" enctype=" ">
<p><b>Please complete the contact us form below:</b></p>
<fieldset class="contact">
<b><legend>Contact Details: </legend><br>
<div> <label for="realName">Name: </label> <input type='text' name='realName' value=""></div>
<div> <label for="email">E-Mail Address: </label> <input type='text' name='email' value=""></div>
<div> <label for="subject">Subject: </label> <input type='text' name='subject' value=""></div>
<div> <label for="body">Message: </label> <textarea name="body" rows="5" cols="30"> </textarea></div></fieldset><br>
<input type="submit" name="send" value="Send Message"/>
<input class='button' align='right' type='reset' value='Reset'/>
<input class='button' align='right' type='button' value='Cancel' onclick='window.location.href="index.php"'/></form>
contactinfo.php:
<html>
<head>
<title>Thanks For Contacting Us</title>
</head>
<body>
<?php
$recipient = ' ';
$email = $POST['email'];
$realName = $POST['realName'];
$subject = $POST['subject'];
$body = $POST['body'];
$messages = array();
if (!preg_match("/[\w+-.~]+@[-\w.!]+$/", $email)) {
$messages[] = "That is not a valid email address.";
}
if (!preg_match("/[\w\ +-\'\"]+$/", $realName)) {
$messages[] = "The real name field must contain only " .
"alphabetical characters, numbers, spaces, and " .
"reasonable punctuation. We apologize for any inconvenience.";
}
$subject = preg_replace('/\s+/', ' ', $subject);
if (preg_match('/\s*$/', $subject)) {
$messages[] = "Please specify a subject for your message.";
}
$body = $_POST['body'];
if (preg_match('/\s*$/', $body)) {
$messages[] = "Your message was blank. Did you mean to say " .
"something?";
}
if (count($messages)) {
foreach ($messages as $message) {
echo("<p>$message</p>\n");
}
echo("<p>Click the back button and correct the problems. " .
"Then click Send Your Message again.</p>");
} else {
mail($recipient,
$subject,
$body,
"From: $realName <$email>\r\n" .
"Reply-To: $realName <$email>\r\n");
echo("<p>Your message has been sent. Thank you!</p>\n");
}
?>
</body>
</html>
isit possible to display the validations next to the forms representative fields instead of them showing on new page?.
Also i am running this on wamp locally, will it send email to my hotmail account or do i need a server for it?
Thanks guys for your help, really appriciate it 🙂
Jay