I have an html form that is validated by php, how do i set the php to check the html form fields and make sure they are not blank, meaning that people can hit the space bar and my php thinks that there is something in the field?
[code=php]<?
session_start();
$errors = array();
if( empty( $_POST[‘name’] ) )
{ // fail error checking
$errors[] = ‘Name is Required’;
}
if( empty( $_POST[’email’] ) )
{
$errors[] = ‘Email is Required’;
}
if( empty( $_POST[’email2′] ) )
{
$errors[] = ‘Confirm Email is Required’;
}
if( !empty( $_POST[’email’] ) && !empty( $_POST[’email2′] ) && $_POST[’email’] != $_POST[’email2′] )
{
$errors[] = ‘Your email addresses do not match’;
}
if( empty( $_POST[‘Company’] ) )
{
$errors[] = ‘Company is Required’;
}
if( empty( $_POST[‘address’] ) )
{
$errors[] = ‘Address is Required’;
}
if( empty( $_POST[‘city’] ) )
{
$errors[] = ‘City is Required’;
}
if( empty( $_POST[‘region’] ) )
{
$errors[] = ‘State is Required’;
}
if( empty( $_POST[‘zip’] ) )
{
$errors[] = ‘Zip is Required’;
}
if( empty( $_POST[‘country’] ) )
{
$errors[] = ‘Country is Required’;
}
// repeat for all validation
if( empty( $_POST[‘Security_Code’] ) )
{
$errors[] = ‘Plese fill in the security code’;
}
elseif( $_POST[‘Security_Code’] != $_SESSION[‘pass’] )
{
$errors[] = ‘The security code you entered is invalid’;
}
if( !empty( $errors ) )
{
?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”
“http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>MARK-10 Force and Torque Measurement</title>
<meta name=”description” content=”Manufacturer of force and torque measuring instruments”>
<meta name=”keywords” content=”force gauges, force gages, torque gauges, torque gages, force indicators, torque indicators, needle sharpness testers, blade sharpness testers, puncture testers, spring testers, tensile testers, pull testers, compression testers, friction testers, friction meters, slip testers, slip meters, slipperiness testers, slipperiness meters, peel testers, bond strength testers, materials testers, force measurement, torque measurement, torque tool calibrators, peel testing, crimp testing, pull testing, compression testing, tension testing, torque analyzers, test stands, manual stands, manual test stands, motorized stands, morized test stands, universal test stands, FORCE GAUGES, FORCE GAGES, TORQUE GAUGES, TORQUE GAGES, FORCE INDICATORS, TORQUE INDICATORS, NEEDLE SHARPNESS TESTERS, BLADE SHARPNESS TESTERS, PUNCTURE TESTERS, SPRING TESTERS, TENSILE TESTERS, PULL TESTERS, COMPRESSION TESTERS, CHATILLON, AMETEK, DILLON, WAGNER, IMADA, SHIMPO, FRICTION TESTERS, FRICTION METERS, SLIP TESTERS, SLIP METERS, PEEL TESTERS, BOND STRENGTH TESTERS, MATERIALS TESTERS, FORCE MEASUREMENT, TORQUE MEASUREMENT, TORQUE TOOL CALIBRATORS, PEEL TESTING, CRIMP TESTING, PULL TESTING, COMPRESSION TESTING, TENSION TESTING, TORQUE ANALYZERS”>
<meta http-equiv=”refresh” content=”3;URL=/inquiries.html”>
<link rel=stylesheet href=”stylesheet2004.css” type=”text/css”>
<script language=”javascript” src=”hide.js” type=”text/javascript”></script>
</head>
<body>
<nobr><div align=”center”><img src=”images/top_force-torque_banner1.gif” alt=”MARK-10: The force gauge and torque gauge source” width=”385″ height=”65″ border=”0″><img src=”images/top_force-torque_banner2.gif” alt=”MARK-10 force gauges, torque gauges, and testing systems” width=”386″ height=”65″ border=”0″></div></nobr>
<nobr><div align=”center”><a href=”/index.html”><img src=”images/top_force-torque_banner3.gif” alt=”MARK-10: A leader in force measurement and torque measurement testing systems” width=”385″ height=”65″ border=”0″></a><img src=”images/top_force-torque_banner4.gif” alt=”Identify a MARK-10 force gauge or torque gauge for your force measurement and torque measurement requirements” width=”386″ height=”65″ border=”0″></div></nobr>
<table border=”0″ width=”770″ cellspacing=”0″ cellpadding=”0″ align=”center”>
<tr>
<td class=”tagline”><img src=”images/we make.jpg” width=”400″ height=”19″></td>
<td align=”right”><img src=”images/home_flag.gif” alt=”USA Flag” width=”19″ height=”14″ border=”0″><span class=”tagline_phone”>888-MARK-TEN</span></td>
</tr>
</table>
<table border=”0″ width=”770″ cellspacing=”0″ cellpadding=”0″ align=”center”>
<tr>
<td id=”navigation” valign=”top” width=”155″>
<!– navigation–>
<script language=”javascript” src=”navigation.js” type=”text/javascript”></script>
<noscript>
<div class=”nav”><a href=”/instruments/index.html”>Products</a></div>
<div class=”nav”><a href=”/applications/index.html”>Applications Gallery</a></div>
<div class=”nav”><a href=”/downloads.html”>Product Literature</a></div>
<div class=”nav”><a href=”/order.html”>How to Order</a></div>
<div class=”nav”><a href=”/about.html”>About Mark-10</a></div>
<div class=”nav”><a href=”/contact.html”>Contact Us</a></div>
<div class=”nav”><a href=”/faq.html”>Frequent Questions</a></div>
<div class=”nav”><a href=”/distributor.html”>Distributors</a></div>
<div class=”nav”><a href=”/tools/angle.html”>Conversion Calculators</a></div>
<div class=”nav”><a href=”/list.html”>Join Mailing List</a></div>
<div class=”nav”><a href=”/index.html”>Home</a></div></noscript>
<!– end navigation–>
</td>
<td id=”spacer” class=”divid”><img src=”images/spacer.gif” alt=”” width=”11″ height=”1″ border=”0″></td>
<td id=”content_table”>
<h1 style=”color: #F00″>Error </h1>
<?php
echo ‘<p>Please correct the following errors :</p>
<ul>
<li>’.implode( ‘</li>’.”n”.'<li>’, $errors ).'</li>
</ul>’.”n”;
?>
</td>
</tr>
</table>
<script language=”javascript” src=”../bottomnav.js” type=”text/javascript”></script>
</body>
</html>
<?php
}
else
{
//sends email via php to the following address
$mailuser = “[email protected]”;
//echo ‘default chosen address: ‘.$mailuser;
$header = “Return-Path: “.$mailuser.”rn”;
$header .= “From: Mark-10 Web Inquiry<“.$mailuser.”>rn”;
$header .= “Content-Type: text/html;”;
$mail_body =
‘The User: ‘.$_POST[name].’ has sent his input.
Name: ‘. $_POST[name] . ‘<br>
Mr:’ . $_POST[Mr] .'<br>
Ms:’ . $_POST[Ms] .'<br>
Title: ‘. $_POST[title] . ‘<br>
email: ‘. $_POST[email] . ‘<br>
confirm email: ‘. $_POST[email2] . ‘<br>
Company: ‘. $_POST[Company] . ‘<br>
Address: ‘. $_POST[address] . ‘<br>
Address: ‘. $_POST[address2] . ‘<br>
City: ‘. $_POST[city] . ‘<br>
State: ‘. $_POST[region] . ‘<br>
Zip: ‘. $_POST[zip] . ‘<br>
Country: ‘. $_POST[country] . ‘<br>
Telephone: ‘. $_POST[telephone] . ‘<br>
Extention: ‘. $_POST[ext] . ‘<br>
fax: ‘. $_POST[fax] . ‘<br>
Application or Question:’ . $_POST[comments] .'<br>
Sales call Needed:’ . $_POST[sales] .'<br>
Catalog:’ . $_POST[SendCatalog] .'<br>
Mailing List:’ . $_POST[AddToMailingList] .'<br>’;
mail ($mailuser, ‘Mark-10 Web Inquiry’, $mail_body, $header);
header(“Location: http://www.mark-10.com/thankyou-inquiry.html”);
}
?>