Reply to Re: VALIDATING MANDATORY FIELDS USING PHP NOT JAVA SCRIPT!?!

Your name:

Reply:


Posted by Ehsan on 05/04/06 09:22

hi,

you can have an array defined which will have the fieldnames as defined
in the form. then have a function say validateFields() in PHP which
will loop through the array and check the value.

if the value is null then your validateFields() will keep adding the
field label and after looping through the array, it will have the full
error message which will be returned. your PHP should check if the
value returned is 1 or not. If 1, then validation was successful
otherwise it will stop further processing and print the returned error
message.

Example:
==============

$fieldsToValidate = array ('field1' => 'field1 Label', 'field2' =>
'field2 Label');

function validateFields()
{
$err = "<font color='#ff0000'>Following fields cannot be left
blank:<ul>";
$errCount = 0;
foreach ($fieldsToValidate as $key => $value)
{
if ($_POST[$key] == "")
{
$err .= "<li>" . $value . "</li>";
$errCount++;
}
}
$err .= "</ul><font>";

if ($errCount > 0)
return $err;
else
return true;
}

Take the returned value and do the rest of processing.

Hope this helps.

Thanks and God Bless!!

Ehsan
http://ehsan.bdwebwork.com

[Back to original 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

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