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:


<!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">
   <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" />
   <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;amp;amp;(!validateModel($_POST['model']) || !validatePrice($_POST['price']) || !validateDescription($_POST['description']) ) ):?>
            <div id="error">
                     <li><strong>Invalid Name:</strong> We want names with more than 3 letters!</li>
                     <li><strong>Invalid E-mail:</strong> Type a Valid Price!</li>
                     <li><strong>Invalid message:</strong> Type a message with at least with 10 letters</li>
            <div id="error" class="valid">
                  <li><strong>Congratulations!</strong> All fields are OK ;)</li>
      <form method="post" id="customForm" action="" enctype="multipart/form-data">
            <label for="model">Model Number</label>
            <input id="model" name="model" type="text" />
            <span id="modelInfo">Please enter your Product Model Number!</span>

            <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>

            <span id="productInfo">Please choose a Product Title!</span>

            <label for="price">Price</label>
            <input id="price" name="price" type="text" />
            <span id="priceInfo">Please enter a Price!</span>

            <label for="photo">Image</label>
            <input style="font-size:13px;" class="file" name="photo" type="file" />
            <span id="photoInfo">Please choose an Image!</span>

            <label for="message">Description</label>
            <textarea id="description" name="description" cols="" rows=""></textarea>

            <input id="send" name="send" type="submit" value="Send" />


This is the validation file:

	function validateModel($model){
		//if it's NOT valid
		if(strlen($model) < 4)
			return false;
		//if it's valid
			return true;

	function validatePrice($price){
		//if it's NOT valid
		if(strlen($price) < 4)
			return false;
		//if it's valid
			return true;

	function validateDescription($description){
		//if it's NOT valid
		if(strlen($description) < 10)
			return false;
		//if it's valid
			return true;

I can't spot the problem, any suggestions?

Hey, thanks for providing the code...you had made my work more easier.

do you know what the problem is?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.