Hi all,
Im trying to add validation to a form to allow PHP to check before its sends the values to another page for them to be uploaded to a database.
The problem i have is that i have taken a, i thought simple PHP validating script off the net and i cant seem to get it to work, its just giving me a blank page. I dont know if the script is outdated, i dont think it is.
The script is here:
<?php
include("validation.php");
?>
<!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" />
<title>Test Area</title>
<link rel="stylesheet" href="test.css" type="text/css" media="screen" />
</head>
<body>
<div id="container">
<h1>Add a Product</h1>
<?if(isset($_POST['send'])&amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp;(!validateModel($_POST['model']) || !validatePrice($_POST['price']) || !validateDescription($_POST['description']) ) ):?>
<div id="error">
<ul>
<?if(!validateModel($_POST['model'])):?>
<li><strong>Invalid Name:</strong> We want names with more than 3 letters!</li>
<?endif?>
<?if(!validatePrice($_POST['price'])):?>
<li><strong>Invalid E-mail:</strong> Type a Valid Price!</li>
<?endif?>
<?if(!validateDescription($_POST['description'])):?>
<li><strong>Invalid message:</strong> Type a message with at least with 10 letters</li>
<?endif?>
</ul>
</div>
<?elseif(isset($_POST['send'])):?>
<div id="error" class="valid">
<ul>
<li><strong>Congratulations!</strong> All fields are OK ;)</li>
</ul>
</div>
<?endif?>
<form method="post" id="customForm" action="" enctype="multipart/form-data">
<div>
<label for="model">Model Number</label>
<input id="model" name="model" type="text" />
<span id="modelInfo">Please enter your Product Model Number!</span>
</div>
<div>
<label for="product">Product</label>
<select class="products" name="products">
<option value="0">Please select an option below</option>
<option value="1">19" LCD TV</option>
<option value="2">22" LCD TV</option>
<option value="3">26" LCD TV</option>
<option value="4">32" LCD TV</option>
<option value="5">37" LCD TV</option>
<option value="6">42" LCD TV</option>
<option value="7">37" Plasma TV</option>
<option value="8">42" Plasma TV</option>
<option value="9">46" Plasma TV</option>
<option value="10">50" Plasma TV</option>
<option value="11">54" Plasma TV</option>
<option value="12">58" Plasma TV</option>
<option value="13">Wall Bracket</option>
<option value="14">Home Cinema System</option>
<option value="15">Bluray Home Cinema System</option>
<option value="16">DVD Recorder</option>
<option value="17">DVD Player</option>
<option value="18">DVD Portable</option>
<option value="">Bluray Recorder</option>
<option value="">Bluray Player</option>
<option value="">Bluray Portable</option>
<option value="">Projector</option>
<option value="">37" LCD TV</option>
<option value="">42" LCD TV</option>
<option value="">Personal Video Recorder (PVR)</option>
<option value="">3D Technology</option>
<option value="">Upright Cleaner</option>
<option value="">Cylinder Cleaner</option>
<option value="">DECT Phone</option>
<option value="">DECT Answer Phone</option>
<option value="">Washing Machines</option>
<option value="">Tumble Dryers</option>
<option value="">Dishwashers</option>
<option value="">Fridge-Freezers</option>
<option value="">Freezers</option>
<option value="">Refridgerators</option>
<option value="">Microwave (Solo)</option>
<option value="">Microwave (Grill)</option>
<option value="">Microwave Combination</option>
<option value="">Kettles</option>
<option value="">Toasters</option>
<option value="">Irons</option>
<option value="">Breadmakers</option>
<option value="">Microsystems</option>
<option value="">Minisystems</option>
<option value="">CD, Radio and Cassette Players</option>
<option value="">Pure Radios</option>
<option value="">Dimplex Fires</option>
<option value="">Convector Heaters</option>
<option value="">Fan Heaters</option>
<option value="">Mens Shavers/Grooming</option>
<option value="">Ladies Shavers/Beauty</option>
<option value="">Straighteners</option>
<option value="">Epilators</option>
<option value="">Stylish Cameras</option>
<option value="">Super Zoom Cameras</option>
<option value="">SD Camcorders</option>
<option value="">HD Camcorders</option>
<option value="">HDD Camcorders</option>
<option value="">Bluray Discs</option>
<option value="">DVD Discs</option>
<option value="">Leads</option>
<option value="">Mini DV Tapes</option>
<option value="">SD/SDHC/SDXC Cards</option>
</select>
<span id="productInfo">Please choose a Product Title!</span>
</div>
<div>
<label for="price">Price</label>
<input id="price" name="price" type="text" />
<span id="priceInfo">Please enter a Price!</span>
</div>
<div>
<label for="photo">Image</label>
<input style="font-size:13px;" class="file" name="photo" type="file" />
<span id="photoInfo">Please choose an Image!</span>
</div>
<div>
<label for="message">Description</label>
<textarea id="description" name="description" cols="" rows=""></textarea>
</div>
<div>
<input id="send" name="send" type="submit" value="Send" />
</div>
</form>
</div>
</body>
</html>
This is the validation file:
<?php
function validateModel($model){
//if it's NOT valid
if(strlen($model) < 4)
return false;
//if it's valid
else
return true;
}
function validatePrice($price){
//if it's NOT valid
if(strlen($price) < 4)
return false;
//if it's valid
else
return true;
}
function validateDescription($description){
//if it's NOT valid
if(strlen($description) < 10)
return false;
//if it's valid
else
return true;
}
?>
I can't spot the problem, any suggestions?