How can I make a piece field validation code a function?
Posted: Sat Sep 19, 2009 11:20 am
I have applied the following validation code to a field that seems to work ok:
Next to the form field, I include <? echo $field1error; ?>
Problem is, I have about 20 more fields that I would like to apply the above validation code. For maintanability sake, there has to be a slick way to make the above in blue a function, that I can apply like so:
function(field1)
function(field2)
function(field3)
Code: Select all
[color=#0000FF]if($_POST['[/color][color=#FF0000]field1[/color][color=#0000FF]'] == NULL){
$reqerrors[] = "Yes";
$cholesterolerror = "\t<br><span class=pred>You must enter a value.</span>\n";
}
elseif(is_numeric($_POST['[/color][color=#FF0000]field1[/color][color=#0000FF]']) && $_POST['[/color][color=#FF0000]field1[/color][color=#0000FF]'] >= 0) {
}
else {
$reqverrors[] = "Yes";
$[/color][color=#FF0000]field1[/color][color=#0000FF]= "\t<br><span class=pred>Invalid value entered.</span>\n";
}[/color]Problem is, I have about 20 more fields that I would like to apply the above validation code. For maintanability sake, there has to be a slick way to make the above in blue a function, that I can apply like so:
function(field1)
function(field2)
function(field3)