I wrote this neat little function to do just that a while back, I use it all the time, it goes like:
function chkReqFields( $field_array, $flag = 'ALL' )
{
for ($i = 0; $i < sizeof($field_array); $i++) {
if ($_POST[$field_array[$i]] && $flag == 'ONE_EXHISTS')
return 1;
if (!$_POST[$field_array[$i]] && $flag == 'ALL')
return 0;
}
if ( $flag == 'ONE_EXHISTS' )
return 0;
else
return 1;
}
as you can see, it has an optional parameter so you can check if all the required fields are set or if one is missing.
I use it like:
if (chkReqFields($required_fields, 'ONE_EXHISTS')) {
if (chkReqFields($required_fields)) {
echo "all fields are set...";
} else {
echo "all fields are not set";
} else {
echo "No fields are set";
}
just create an array with the names of the required fields add pass it to the function. This works well for a few different situations...