<div class="form-item"> <input type="hidden" value="" name="attendNothing" /> <input type="checkbox" id="attend-nothing" [[+fi.attendNothing:notempty=`checked="checked"`]] value="Ja" name="attendNothing"> <label for="attend-nothing">können leider nicht teilnehmen</label> </div> <div class="form-item"> <input type="hidden" value="" name="attendCeremony" /> <input type="checkbox" id="attend-ceremony" [[+fi.attendCeremony:notempty=`checked="checked"`]] value="Ja" name="attendCeremony"> <label for="attend-ceremony">nehmen an der Trauungszeremonie teil</label> </div> <div class="form-item"> <input type="hidden" value="" name="attendReception" /> <input type="checkbox" id="attend-reception" [[+fi.attendReception:notempty=`checked="checked"`]] value="Ja" name="attendReception"> <label for="attend-reception">nehmen am Apero teil</label> </div> <div class="form-item"> <input type="hidden" value="" name="attendParty" /> <input type="checkbox" id="attend-party" [[+fi.attendParty:notempty=`checked="checked"`]] value="Ja" name="attendParty"> <label for="attend-party">nehmen am Essen / Fest teil</label> </div> [[!+fi.error.attendNothing:notempty=` <div class="field-msgs"> <span class="error"> [[!+fi.error.attendNothing]] </span> </div> `]]
$scriptProperties['customValidators'] = 'requiredOneOfMany';
$scriptProperties['validate'] = 'attendNothing:requiredOneOfMany';
$scriptProperties['attendNothing.vTextRequiredOneOfMany'] = 'One Attend Option needs to be choosen';
$modx->runSnippet('FormIt', $scriptProperties);
<?php
$fields = $modx->getOption('fields',$scriptProperties,'');
$fields = explode(',',$fields);
$success = false;
foreach ($fields as $field){
// only check fields who's key contains the string "attend"
if(strpos($field->$key,'attend') >= 0){
$fieldrequest = $modx->getOption($field, $_REQUEST);
if (!empty($fieldrequest)){
$success = true;
}
}
}
return $success;
This question has been answered by janwidmer. See the first response.
<?php
//$modx->log(modX::LOG_LEVEL_ERROR, 'in my validator' ); // just to be sure you fire the validator
$fields = $validator->fields;
$success = false;
if($fields['attendNothing'] == 'Ja' || $fields['attendCeremony'] == 'Ja' || $fields['attendReception'] == 'Ja' || $fields['attendParty'] == 'Ja'){
//$modx->log(modX::LOG_LEVEL_ERROR, 'At least one field is set');
$success = true;
}
if(!$success){
$validator->addError('attendNothing','Eine der Optionen muss ausgewählt werden');
}
return $success;