Jazajay
Active Member
Please see the solution if you get a 500 error due to a bad server configuration.
Below is a fully functioning XHTML contact form that will validate to strict and is accessible to people with disabilities.
Please read user notes at the bottom to get it to work on your site, easy steps and you don't need to be a geek to get it to work.
Post 5 contains an upgraded version with styling, and some minor improvements using some CSS3 that degrades nicely.
Version1.01.
1. Please keep the last comment in out of curtsy, but you don't have to if you want to seem amazing to your boss.
2. All you need to do is edit the bolded lines, html comments explain what needs changing and that's it just copy and paste it and you have a fully working contact page for your site.
3. The file needs to be saved as a php file so something like contact-me.php, not .html or .asp as we are using PHP code.
Aren't I nice it even validates.
If anyone would like any improvements just let me know, or if you run into problems, and I'm sure me or someone on here will help you out with them.
Jaz
Below is a fully functioning XHTML contact form that will validate to strict and is accessible to people with disabilities.
Please read user notes at the bottom to get it to work on your site, easy steps and you don't need to be a geek to get it to work.
Post 5 contains an upgraded version with styling, and some minor improvements using some CSS3 that degrades nicely.
Version1.01.
User notes<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Contact us</title>
</head>
<body>
<?php
if(isset($_POST['name']))
{
$count=0;
$err="Please fix the errors below to be able to contact me: <br />";
if(!empty($_POST["name"])){
$from = $_POST["name"];
}else{
$count++;
$err.="Please enter your name<br />";
} if(!empty($_POST["email"])){
$email_check = preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $_POST["email"]);
if($email_check!==0){
$email=$_POST["email"];
}else{
$count++;
$err.="Your email address appears to be wrong,<br />";
}
}else{
$count++;
$err.="You need to enter an email address so I can contact you<br />";
} if(!empty($_POST['mess'])){
$content = "This message is from $from whose email address is $email.\r\n-----------\r\n ";
$content = $content . $_POST["mess"];
$content = strip_tags(wordwrap($content, 70));
}else{
$count++;
$err.="Your message was blank";
}
if($count==0){
mail('[email protected]', 'Website inquiry', $content)?>
<!--Change the email address you want it to be sent to in the first bolded statement, and the subject of the email address goes in the second bolded section.-->
<h2>Success</h2>
<p>
Your message has been sent and I always aim to reply to all emails within 48hours.
</p>
<p>
Thank you for taking the time to contact me.
</p>
<p>
<i>Add your name or company name in here.</i>
<!-- Add your name here-->
</p>
<p>
<a href="">Back to our home page</a>
<!-- Add your domain name in between the quote marks ie http://www.yoursite.com/-->
</p>
<?php }else{?>
<h2><?php if($count>1){echo $count;?> errors <?php }else{?>1 error <?php }?>occured</h2>
<p>
<?php echo $err;?>
</p>
<form method="post" action="">
<p><label for="name">Name: </label></p>
<p>
<input type="text" name="name" id="name"<?php if(!empty($_POST["name"])){?> value="<?php echo $_POST['name'];?>"<?php }?> />
</p>
<p><label for="email">Email: </label></p>
<p>
<input type="text" name="email" id="email"<?php if(!empty($_POST["email"])){?> value="<?php echo $_POST['email'];?>"<?php }?> />
</p>
<p><label for="message">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="message"><?php if(!empty($_POST["mess"])){?><?php echo $_POST['mess'];}?></textarea>
</p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }
}else{
?>
<form method="post" action="">
<p><label for="name">Name: </label></p>
<p>
<input type="text" name="name" id="name" />
</p>
<p><label for="email">Email: </label></p>
<p>
<input type="text" name="email" id="email" />
</p>
<p><label for="message">Message: </label></p>
<p>
<textarea name="mess" cols="50" rows="20" id="message"></textarea>
</p>
<p><button type="submit">Contact me</button></p>
</form>
<?php }?>
<!--Contact form courtesy of Jazajay at designforums.co.uk-->
</body>
</html>
1. Please keep the last comment in out of curtsy, but you don't have to if you want to seem amazing to your boss.
2. All you need to do is edit the bolded lines, html comments explain what needs changing and that's it just copy and paste it and you have a fully working contact page for your site.
3. The file needs to be saved as a php file so something like contact-me.php, not .html or .asp as we are using PHP code.
Aren't I nice it even validates.
If anyone would like any improvements just let me know, or if you run into problems, and I'm sure me or someone on here will help you out with them.
Jaz