|
Posted by Chris Lott on 01/10/06 02:54
What I have is a form with 45 data fields... if any of a selected 35
of those fields is empty, I want to have the user go back. So I can't
loop over the entire _POST array. So I thought I would put the names
of the fields I *do* want to check into an array and check.
So this won't work:
> foreach($array as $key=>$value){
> if(empty($value)){
> $err_msg= "$key is empty";
> break;
Because the array is the names of the fields, and I want to check each
variable in _POST that matches. So instead of writing
if (empty($_POST['forma'])
if (empty($_POST['formb'])
etc
I would do something like
$fieldstocheck = array('forma', 'formb');
foreach ($fields as $thisfield) {
if (empty($_POST[$thisfield])) {
set the error flag;
}
But that doesn't seem to work.
Eventually I will use the array to associate error text:
$fieldstocheck = array('forma' => 'You must enter field A', 'formb' =>
''Field B is your age in years and is required');
etc
c
Navigation:
[Reply to this message]
|