I’m not sure where you get the $name variable from but I’d be very surprised if that contained anything useful in this case. The problem you’re having with the variables you are trying to use is that they are no longer available or can not be brought into the function’s scope (without altering the eform core). $desc does not exist by the time the function is called. $rMsg is never within the scope of the function. This is unfortunate in your case but without hacking the eform code itself there’s no way around it.
Below is a more or less generic function that will test if any of the declared fields (see comments in code) have been filled in and if at least one but not all are filled in set an error.
<?php
# Snippet: eFormValidation
function validateFields(&$fields,&$vMsg,&$rMsg){
//declare optional fields (name => description)
//set these to your form fields that you want tested
$optionalFields = array(
'name2_1' => 'Name 2 Desc',
'field2' => 'Field 2',
'field3', => 'Field 3',
'field4', => 'Field 4',
'field5' => 'Field 5'
);
//step through the fields, count how many are missing
foreach($optionalFields as $ofield => $oDescr){
if($fields[$ofield] !=''){
$filledInFields++;
else
$missingFields[] = $oDesc;
}
//if at least 1 field is filled in but not all
//
if($filledInFields > 0 && $filledInFields < count($optionalFields)){
$vMsg['Optional Fields'] = 'You have only filled in some of the optional fields. You must also fill in' . implode(', ',$missingFields);
//this only works if you can bring the $rClass into scope
//you'll have to hack the eform code to do this
//either by making the $rClass global (both in eform and here)
//or by adjusting (including it in) the event call and reference it in this function decalration
foreach($missingFields as $ofield){
$rClass($ofield) = 'required' //make same as &requiredClass (as set in snippet call)
}
//--//
}
return true;
}
?>