hey all...Maybe u can help me out here...
I'm trying to write a data validation class and seem to be having some issues with my output.
here's the code:
<?PHP
class dataValidate
{
var $error = false; //Boolean value showing whether or not error has occurred.
var $message; //String of error message
function dataValidate($postVars)
{
$this->$error = false;
if($postVars['listOfFields'])
{
$listOfFields = explode(",",$postVars['listOfFields']);
foreach($listOfFields as $value)
{
switch($value)
{
case "CustEmail1":
if($postVars['CustEmail1'] == "")
{
$this->$error = true;
$this->$message = $this->$message."Email address is required.<BR>\n";
}
else if(eregi("[^a-zA-Z0-9@.-_]",$postVars['CustEmail1']))
{
$this->$error = true;
$this->$message = $this->$message."Your email address contains invalid characters.<BR>\n";
}
else if(strlen($postVars['CustEmail1']) > 60)
{
$this->$error = true;
$this->$message = $this->$message."Your email address cannot be greater than 60 characters in length.<BR>\n";
}
break;
case "CustEmail2":
if($postVars['CustEmail1'] != $postVars['CustEmail2'])
{
$this->$error = true;
$this->$message = $this->$message."The Emaill addresses you entered do not match.<BR>\n";
}
break;
case "CustFirstName":
if($postVars['CustFirstName'] == "")
{
$this->$error = true;
$this->$message = $this->$message."First name is required.<BR>\n";
}
else if(eregi("[^a-zA-Z.[:space:]-]",$postVars['CustFirstName']))
{
$this->$error = true;
$this->$message = $this->$message."Your first name can only contain the characters a-z, - and spaces.<BR>\n";
}
if(strlen($postVars['CustFirstName']) > 30)
{
$this->$error =true;
$this->$message = $this->$message."Your first name cannot exceed 30 characters.<BR>\n";
}
break;
}
}
}
else
{
$this->$error = true;
$this->$message = "There is no list of variables defined.<BR><BR>\n\n";
}
}
}
$newData = new dataValidate($_POST);
if($newData->$error == true)
{
print($newData->$message);
print("<HTML><FORM ACTION=\"classes.php\" METHOD=POST>\n<INPUT TYPE=TEXT NAME=\"listOfFields\">\n<INPUT TYPE=SUBMIT>");
}
else
{
echo($newData->$message);
print("\n\n");
}
?>
and here's the output:
<BR>
1First name is required.<BR>
<HTML><FORM ACTION="classes.php" METHOD=POST>
<INPUT TYPE=TEXT NAME="listOfFields">
<INPUT TYPE=SUBMIT
In theory, this should print "Email address is required" and then "First name is required" on separate lines followed by the simple form when I enter "CustEmail1,CustFirstName" into the form.
Also, where is the 1 before the "first Name is required" coming from?
Maybe I'm jsut not awake enough to figure it out, i don't know...
It's probably very simply...
BTW I didn't post the form that this would be used with. This is just in its early stages...
Chris