You are here: Re: [PHP] Dynamic Array Index using Variable « PHP « IT news, forums, messages
Re: [PHP] Dynamic Array Index using Variable

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация