Hey Everyone,
I am just about finishing up on a contact page with all the fields working (Name, address, phone number and message) and a submit button.
What I need is the code for submitting an error when the fields are not typed in.
I have pasted the code below. But does not seem to work
Have I made this code to complicated or is there an easier way?
<!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>Combined Feedback Form</title>
</head>
<body>
<?php
$username = $POST['username'];
$useraddr = $POST['useraddr'];
$phoneno = $POST['phoneno'];
$comments = $POST['comments'];
$sent = $_POST['sent']
$form ="<form action=\"$_SERVER['PHP_SELF']\"method=\"post\">";
$form.="Name:<input type=\"text\" name=\"username\"";
$form.="size=\"30\"value=\"$username\" > <br> <br>
$form.="Email:<input type=\"text\" name=\"useraddr\"";
$form.="size=\"30\"value=\"$useraddr\" > <br> <br> $form.="Phone Number:<input type=\"numbers\" name=\"phoneno\"";
$form.="size=\"30\"value=\"$phoneno\" > <br> <br>
$form.="value=\"Send Form\"></form>";
if($sent)
{ $valid=true;
if( !$username)
{ $errmsg.="Enter your name:<br>"; $valid=false; }
if( !$useraddr)
{ $errmsg.="Enter email address:<br>"; $valid=false; }
if( !$phoneno)
{ $errmsg.="Enter your phone number:<br>"; $valid=false; }
}
if( $valid !=true ){echo( $errmsg . $form ); }
else
{ $to = "info@globeunited.org";
$re = "Feedback form" $username";
$msg = $comments;
$headers = "From: $useraddr \r\n";
if( mail( $to, $re, $msg, $headers ))
{ echo("Thanks for your comments, $username");}
}
?>
</body></html>
if( $useraddr )
{ $errmsg .="Enter email address:<br>"; $valid = false }
else
{
$useaddr = trim( $useaddr );
$_name = "/^[-!$%&\'*+\\.\/0-9=?A-Z^_{|}]+";
$_host = "([-0-9A-Z])+\.)+";
$_tlds = "([-0-9A-Z] {2,4}$/i";
if( !preg_match($_name."@".$_host.$_tlds,$useraddr) )
{
$errmsg .= "Email address has incorrect format!<br>";
$valid = false; }
}
I would appreciate any help!
Thanks