I WANT to pass 3 variables to a function 1 of them being an array.
After filling out my web form and submitting it the script sets the style sheets for the page, checks for errors, prints error information (if any), and then pulls up the next logical form element (last step broken).
The problem is, instead of passing the error information as a variable the information is echoed and in order to maintain the look and feel to the site I have to create the headers (unique to the error information) BEFORE the error checks.. Example below: "..." is irrelevant information purposefully truncated.
Code: Select all
include ('includes/inc.funct.newvalid.php');
<style>
...
</style>
<fieldset class='error'>"; //I NEED TO REMOVE THIS AND PASS $ERR as array
//WHERE $ERR = ['number of error messages']['custom error message']['custom error message']
// Loop through the list, validate information as it's passed
foreach (array_keys($_POST) as $key)
{
$$key = $_POST[$key];
$err = $err + VALIDATE($key, ${$key}); //Validate Data $err = # of err msgs returned from function.
...
The data is passed through a minimum of 2 functions during this call.. Represented below (all functions are formatted the same).
First Function (VALIDATE)
Code: Select all
function VALIDATE($label, $information)
{
if($label === "FNAME" || $label === "MNAME" || $label === "LNAME") //self explanitory
{
switch ($label) // change label to human readable information
{
case "FNAME";
$label = "<u>first name</u>";
break;
case "MNAME";
$label = "<u>middle name</u>";
break;
case "LNAME";
$label = "<u>last name</u>";
break;
}
$err = NOTNULL($label, $information); // Make sure field isn't blank
if(empty($err)) // if field is NOT blank
{
$err = NAMECHK($label, $information); // Make sure field meets criteria
return $err; //return the number of error messages found
}
else{return $err;} //return the number of error messages found
}
elseif ...
I need to pass an array to the previous function from the main script, to this function, and change the echo statement to an array assignment..
SECOND FUNCTION (NOTNULL)
Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////////////
function NOTNULL($label, $information)
{
if(empty($information))
{
$err++;
echo "<font color='red'>Error! You left your <u> $label </u> blank!</font><br />";
return $err;
}
else{return;}
}
Code: Select all
$err['0']++;
$err['$err['0']'] = "<font color='red'>Error! You left your <u> $label </u> blank! </font><br />";
The problem is - the way I have it laid out right now I HAVE to print the fieldset (first code block) BEFORE I do my validation. Instead of passing the error messages through a variable array and printing the fieldset only IF there is an error. If everything passes without an error then I have a fieldset I don't want or need. If it fails I does what I want it to do. (Finishes the field set with the echo'ed information).
I need fresh eyes on my code because mine are worn out.. I'm not seeing what I need to do to reformat this and get it working as intended not as expected.
Kedaeus