I have set up the following server side code to validate new user form input. I'm not done with it yet (still need to validate email etc - BTW it is a low traffic site so using server side scripting is not an issue). Before I go further with it I would like toknow how to have ALL data fields checked for "malicious scripters" by using the HTMLSpecialChars() function. How can I do that with out adding the test individually to all of the fields below - ie how can I have it automatically check any data entry field? Thanks in advance for any help (yes, I'm a struglling beginner :-)
//create short variables
$username = strtoupper(ltrim($_POST['u
sername'])
);
$firstname = ucfirst (ltrim($_POST['firstname']
));
$lastname = ucfirst (ltrim($_POST['lastname'])
);
$address = ltrim($_POST['address']);
$address2 = ltrim($_POST['address2']);
$city = ltrim($_POST['city']);
$zip = ltrim($_POST['zip']);
$email = strtolower(ltrim($_POST['e
mail']));
$homephone = ltrim($_POST['homephone'])
;
$workphone = ltrim($_POST['workphone'])
;
$cellphone = ltrim($_POST['cellphone'])
;
$password = ltrim($_POST['password']);
$password_ck = ltrim($_POST['password_ck'
]);
// Test whether the form has been submitted in the first place
if (isset($_POST['Submit']))
{
// Test whether your required field is blank
if (empty($username))
{
$ERRusername = TRUE;
$ERRusernameMsg = "You must enter member name";
$success = FALSE;
}
if (empty($firstname))
{
$ERRfirstname = TRUE;
$ERRfirstnameMsg = "You must enter first name";
$success = FALSE;
}
//first name validation
if (!eregi("^[a-z]*$",$firstn
ame))
{
$ERRfirstname_alpha = TRUE;
$ERRfirstname_alphaMsg = "Use only alpha characters.";
$success = FALSE;
}
if (empty($lastname))
{
$ERRlastname = TRUE;
$ERRlastnameMsg = "You must enter last name";
$success = FALSE;
}
//last name validation
if (!eregi("^[a-z]*$",$lastna
me))
{
$ERRlastname_alpha = TRUE;
$ERRlastname_alphaMsg = "Use only alpha characters.";
$success = FALSE;
}
if (empty($address))
{
$ERRaddress = TRUE;
$ERRaddressMsg = "You must enter an address";
$success = FALSE;
}
if (empty($city))
{
$ERRcity = TRUE;
$ERRcityMsg = "You must enter a city";
$success = FALSE;
}
if (empty($zip))
{
$ERRzip = TRUE;
$ERRzipMsg = "You must enter zipcode";
$success = FALSE;
}
//zip code validation
if (!ereg("^([0-9]{5})$",$zip
))
{
$ERRzip_int = TRUE;
$ERRzip_intMsg = "Zipcode must contain 5 digits.";
$success = FALSE;
}
if (empty($email))
{
$ERRemail = TRUE;
$ERRemailMsg = "You must enter email address";
$success = FALSE;
}
if (empty($homephone))
{
$ERRhomephone = TRUE;
$ERRhomephoneMsg = "You must enter your home phone";
$success = FALSE;
}
if (empty($password))
{
$ERRpassword = TRUE;
$ERRpasswordMsg = "You must enter password";
$success = FALSE;
}
if (strlen($password)>12 OR strlen($password)<5)
{
$ERRpassword_len = TRUE;
$ERRpassword_lenMsg = "Password must be between 5 and 12 characters. Try again";
$success = FALSE;
}
if (empty($password_ck))
{
$ERRpassword_ck = TRUE;
$ERRpassword_ckMsg = "You must re-enter password";
$success = FALSE;
}
if (($password)!=($password_c
k))
{
$ERRpasswords_not_eq = TRUE;
$ERRpasswords_not_eqMsg = "Passwords entered were not the same.";
$success = FALSE;
}
}// End of POST test
Start Free Trial