Php form Validation Help Please
Posted: Sun Oct 11, 2009 10:07 pm
I am making a form that needs to validated to make sure that all of the fields have been filled in. I would like messages to appear next to any fields that have not been filled in when the user tries to submit the form. Once the form has been filled in correctly it is meant to email the information to me. But my code does not work, the page just shows up as blank white...
Here is my code. Don't really do much php and am very new at it (not surprised it doesn't work). Any help to get this working would be greatly appreciated. Thanks
Here is my code. Don't really do much php and am very new at it (not surprised it doesn't work). Any help to get this working would be greatly appreciated. Thanks
Code: Select all
<?php
//Create variables for form data
$submit = $_POST['submit'];
$name = strip_tags($_POST['name']);
$lname = strip_tags($_POST['lname']);
$email = strip_tags($_POST['email']);
$city = strip_tags($_POST['city']);
$postcode = strip_tags($_POST['postcode']);
$type = strip_tags($_POST['type']);
$workname = strip_tags($_POST['workname']);
$agree = strip_tags($_POST['agree']);
$errors= 0;
?>
<!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=utf-8" />
<meta name="description" content="Arun Books is a print to demand publisher which encourages new writers to publish their work." />
<meta name="keywords" content="arun, books, publishing, authors, new writers, new zealand" />
<title>Arun Books</title>
<style type="text/css">
<!--
body {
background-image: url(Pictures/Graphics/Main-Background.jpg);
background-repeat: repeat-x;
background-color: #0e66c8;
}
-->
</style>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body,td,th {
font-family: Georgia, Times New Roman, Times, serif;
}
a:link {
color: #009;
text-decoration: none;
}
a:visited {
color: #009;
text-decoration: none;
}
a:hover {
color: #009;
text-decoration: underline;
}
a:active {
text-decoration: none;
color: #009;
}
-->
</style>
<script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>
</head>
<body>
<a name="top" id="top"></a>
<div id="wrapper">
<div id="banner"></div>
<div id="contentFooterBG">
<div id="content">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="23%" height="630" valign="middle"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="180" height="630" class="navBar" id="FlashID">
<param name="movie" value="Flash/ArunBooks Menu Bar.swf" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="Scripts/expressInstall.swf" />
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Flash/ArunBooks Menu Bar.swf" width="180" height="630">
<!--<![endif]-->
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<param name="expressinstall" value="Scripts/expressInstall.swf" />
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object></td>
<td width="77%" rowspan="2" class="heading" style="padding-right:10px"><p>Get Your Work Published</p>
<p class="bodyText">We are pleased you want to get you're work published. This could be the beginning of a long relationship with literature and Arun Books. Please fill in the form below about your personal details and details about the work you want us to publish. Please fill in all fields.</p>
<form id="form1" name="form1" method="post" action="publish.php">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td width="37%" align="right" class="bodyTextNoAlign"><label for="name" class="bodyTextNoAlign"> First Name:
</label></td>
<td width="63%"><div align="left" class="bodyText">
<input name="name" type="text" id="name" size="40" maxlength="40" />
*<?php
if ($submit){
if (!$name){
echo '<style="color:#C00">Please enter a your name.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td align="right" class="bodyTextNoAlign"><label for="lname" class="bodyTextNoAlign">
Last Name:
</label></td>
<td class="bodyText"><div align="left">
<input name="lname" type="text" id="lname" size="40" maxlength="40" />
*
<?php
if ($submit){
if (!$lname){
echo '<style="color:#C00">Please enter a your last name.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td class="bodyTextNoAlign"><div align="right">
<label for="email">Email Address:</label>
</div></td>
<td class="bodyText"><div align="left">
<input name="email" type="text" id="email" size="40" maxlength="40" />
*<?php
if ($submit){
if (!$email){
echo '<style="color:#C00">Please enter a your e-mail.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td class="bodyTextNoAlign"><div align="right">
<label for="address">Address:</label>
</div></td>
<td class="bodyText"><div align="left">
<input name="address" type="text" id="address" size="40" maxlength="40" />
*<?php
if ($submit){
if (!$address){
echo '<style="color:#C00">Please enter a your address.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td class="bodyTextNoAlign"><div align="right">
<label for="city">City:</label>
</div></td>
<td class="bodyText"><div align="left">
<input name="city" type="text" id="city" size="40" maxlength="40" />
*<?php
if ($submit){
if (!$city){
echo '<style="color:#C00">Please enter a your city.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td class="bodyTextNoAlign"><div align="right">
<label for="postcode">Post Code:</label>
</div></td>
<td class="bodyText"><div align="left">
<input name="postcode" type="text" id="postcode" size="10" maxlength="10" />
</div></td>
</tr>
<tr>
<td class="bodyTextNoAlign"><div align="right">
<label for="type">Type of Work:</label>
</div></td>
<td class="bodyText"><div align="left">
<select name="type" id="type">
<option value="Novel">Novel</option>
<option value="Non-fiction">Non-fiction</option>
<option value="Children's Book">Children's Book</option>
<option value="Photographic">Photographic</option>
<option value="Poetry">Poetry</option>
<option value="Other">Other</option>
</select>
*
<?php
if ($submit){
if (!$type){
echo '<style="color:#C00">Please enter the type of work you want Arun Books to publish.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td align="right" class="bodyTextNoAlign"><label for="workname">
Name of Work:
</label></td>
<td><div align="left"><span class="bodyTextNoAlign">
<input name="workname" type="text" id="workname" size="40" maxlength="40" />
*
</span>
<?php
if ($submit){
if (!$workname){
echo '<style="color:#C00">Please enter the name of your work you wnat to publish.</style>';
$errors = 1;
?>
</div></td>
</tr>
<tr>
<td align="right" class="bodyTextNoAlign">
<div align="right">
<?php
if ($submit){
if (!$agree){
echo '<style="color:#C00">You must agree to the terms and conditions if you want Arun Books to publish your work.</style>';
$errors = 1;
?>
<input type="checkbox" name="agree" id="agree" />
</div></td>
<td><div align="left"><span class="bodyTextNoAlign">I agree to the <a href="terms.html">terms and conditions</a> of publishing my work with Arun Books.</span></div></td>
</tr>
<tr>
<td colspan="2" class="bodyTextNoAlign"><label for="submit"></label>
<input name="submit" type="image" class="imageCentre" id="submit" src="Pictures/Graphics/Publish.gif" /></td>
</tr>
<tr class="bodyTextNoAlign">
<td colspan="2"> </td>
</tr>
</table>
</form>
<p class="bodyText"> </p>
<p class="bodyText"> </p></td>
</tr>
<tr>
<td height="100%"> </td>
</tr>
</table>
</div>
<div id="footer">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%">© Arun Books | <a href="../contact.html">Contact Us</a> | <a href="#top">Top</a></td>
<td width="50%"><div align="right">Site by Avario Babushka</div></td>
</tr>
</table>
</div>
</div>
</div>
<script type="text/javascript">
<!--
swfobject.registerObject("FlashID");
//-->
</script>
</body>
</html>
<?php
$emailSubject = 'Arun Books Publication Request';
$webMaster = 'avario@hotmail.com';
if ($submit){
if ($erorrs == 0){
$body = <<<EOD
<br><hr><br>
<b>Arun Books - Publication Request</b><br>
<hr>
Stu, this is a publication request from someone who filled in the form on the Arun Books website.<br>
From $name $lname<br>
$email<br>
$Adress<br>
$city<br>
$postcode<br>
Type of Work: $type<br>
Name of Work: $workname<br>
Please email them to notify them if they have been accepted and with further details.
EOD;
$headers = "From: $email\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* results rendered as HTML */
echo header ("Location:../pubsuccess.html")
?>