View Single Post
  #2 (permalink)  
Old 05-30-06, 01:27 PM
astrkalj's Avatar
astrkalj astrkalj is offline
Newbie Coder
 
Join Date: May 2006
Location: Saint Louis, Missouri
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Woah! Talk about bad code!

This is the way I would have done it:

HTML (email.html)
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Send Us An E-Mail!</title>
</head>
<body>
<form name="send_email" id="send_email" method="post" action="email.php">
<div><strong>Full Name:</strong> <input type="text" name="full_name" id="full_name" maxlength="100" /></div>
<div><strong>E-Mail Address:</strong> <input type="text" name="email_address" id="email_address" maxlength="100" /></div>
<div><strong>Message:</strong> <textarea name="message" id="message"></textarea></div>
<div><input type="submit" name="submit" id="submit" value="Submit E-Mail" /> <input type="reset" name="reset" id="reset" value="Reset Form" /></div>
</form>
</body>
</html>

PHP (email.php);
PHP Code:

<?php

if(!isset($_POST['submit'])) {
        include 
"email.html";
        exit();
} else {
        
$errors = array();
        
$full_name trim($_POST['full_name']);
        
$email_address trim($_POST['email_address']);
        
$message trim($_POST['message']);
        
$full_name htmlentities(strip_tags(preg_replace("/(\!|\@|\#|\$|\%|\^|\&|\*|\(|\))/"""$full_name)));
        if(!
preg_match("/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/"$email_address)) {
                
$errors['email_address'] = "Invalid E-Mail Address!";
        }
        if(
count($errors) != 0) {
                echo 
$errors;
                exit();
        } else {
                
// ...
        
}
}
?>
Reply With Quote