Location: PHPKode > scripts > PHP Form to Mail > formmail_light/www/formmail_form.php
<?php
// The script for processing mail

// Copyright 2009, Robert Rook
// Released under the terms of the
// ABD Free Source Code Licence.
require('formmail.php');
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>

<title> AdvanceByDesign Form to Mail (Light) </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
body {
	padding:10px;
	margin:0;
	background-color:#CCC;
	font-family:Verdana,Helvetica,Arial,sans-serif;
	font-size:100%;
	color:#777;
}
h1 {
	font-size:1.6em;
	padding:0;
	margin:0;
	clear:none;
}
h2 {
	font-size:1.4em;
	padding:0;
	margin:0;
	clear:none;
	color:#AAA;
}
.mail_box {
	width:430px;
	padding:10px;
	background-color:#FFF;
	font-size:0.7em;
	border:1px solid;
	border-color:#EEE #333 #333 #EEE;
}
.row {
	padding:2px;
	clear:both;
}
.row input {
	width:60%;
	float:right;
	border:1px solid #AAA;
	color:#777;
}
.row textarea {
	width:60%;
	float:right;
	border:1px solid #AAA;
	color:#777;
}
.row .submitbutton {
	background-color:#EEE;
	color:#000;
	border:1px solid;
	border-color:#EEE #333 #333 #EEE;
}
.error_box {
	margin:2px;
	padding:5px;
	clear:both;
	border:1px solid #F99;
	background-color:#FEE;
	color:#900;
	display:none;
}
.header_box {
	padding:6px;
	font-size:100%;
	background-color:#FFE;
	border:1px solid;
	border-color:#AAA #EEE #EEE #AAA;
}
.footer_box {
	clear:both;
	padding:10px;
	text-align:center;
	font-size:0.8em;
}
b {
	color:#F00;
}
</style>
<script language="Javascript" type="text/Javascript">
<!--
function GetObj(idObj) {
	if(document.getElementById) {
		return document.getElementById(idObj);
	} else if(document.all) {
		return document.all[idObj];
	}
	return null;
}
function HighlightField(idField,szError) {
	if(szError==false) {
		// Remove highlighting for this field
		GetObj(idField).style.borderColor = "#AAA";
		GetObj(idField+"_error").style.display = "none";
	} else {
		// Highlight field and show error
		GetObj(idField).style.borderColor = "#F99";
		GetObj(idField+"_error").style.display = "block";
		GetObj(idField+"_error").innerHTML = szError;
	}
	return;
}
function ValidateEmail() {
	test = GetObj("id_email").value.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$/i);

	if(test==null) {
		HighlightField("id_email","Please provide a valid email address.");
		return false;
	} else {
		HighlightField("id_email",false);
	}
	return true;
}
function ValidateName() {
	if(GetObj("id_name").value.length<2) {
		HighlightField("id_name","Please provide a name.");
		return false;
	} else {
		HighlightField("id_name",false);
	}
	return true;
}
function ValidateComments() {
	if(GetObj("id_comments").value.length<5) {
		HighlightField("id_comments","Please provide a message if you wish to contact us.");
		return false;
	} else {
		HighlightField("id_comments",false);
	}
	return true;
}
function ValidateForm() {
	if(!ValidateEmail()) { return false; }
	if(!ValidateName()) { return false; }
	if(!ValidateComments()) { return false; }
	GetObj("id_submit").disabled = "disabled";
	return true;
}
// -->
</script>

</head>
<body>

<div class="mail_box">

<div class="header_box">
<h1>Contact us</h1>
<h2>Send us a letter</h2>

<p>Please fill out the contact form below and click
the "Send" button to drop us a letter!</p>
</div>

<?php
// If any errors have occured, show to the visitor
if(isset($err) && strlen($err)) {
	echo "<div class=\"error_box\" style=\"display:block;\">";
	echo "<p>Your mail has not been\n";
	echo "recieved for the following reasons:\n<ul>{$err}</ul></p></div>\n";
}
?>
<form method="post" action="formmail_form.php" onsubmit='Javascript:return (ValidateForm()==true?true:false);'>
<div class="row"><b>*</b> = Denotes required field</div>
<div class="row">&nbsp;</div>
<div class="row"><input type="text" id="id_name" name="name" value="<?=(isset($_POST['name'])?$_POST['name']:"");?>" onchange='Javascript:ValidateName();'>Your name<b>*</b></div>
<div class="error_box" id="id_name_error"></div>
<div class="row"><input type="text" id="id_email" name="email" value="<?=(isset($_POST['email'])?$_POST['email']:"");?>" onchange='Javascript:ValidateEmail();'>Email address<b>*</b></div>
<div class="error_box" id="id_email_error"></div>
<div class="row"><textarea rows="7" cols="30" id="id_comments" name="comments" onchange='Javascript:ValidateComments();'><?=(isset($_POST['comments'])?$_POST['comments']:"");?></textarea>Comments<b>*</b></div>
<div class="error_box" id="id_comments_error"></div>
<div class="row"><input type="submit" id="id_submit" class="submitbutton" value="Send"></div>
</form>

<div class="footer_box">
Form to Mail (Light) script, developed by AdvanceByDesign<br>
<a href="http://www.advancebydesign.com" target="_blank">
http://www.advancebydesign.com</a>
</div>
</div>

</body>
</html>
Return current item: PHP Form to Mail