function help
Posted: Tue Aug 19, 2003 5:49 am
Hi, i am using the following function to try validate a form :-
In my main script I use the following piece of code to check if the form is valid or not. It does work, I just want to know if their is a better/correct way of doing it.
Code: Select all
<?php
function CheckForm($var)
{
$valid = TRUE;
IF (empty($var['name'])) {
$error = array('Please Enter Name');
$valid = FALSE;
}
IF (empty($var['location'])) {
$error[] = 'Please Enter Location';
$valid = FALSE;
}
for ($i = 0; $i<= count($error);$i++)
{
echo $error[$i].'<br>';
}
return $valid;
}
?>Code: Select all
<?
IF (CheckForm($_POST) == FALSE) {
echo "try again";
break;
}
?>