Hello snathan,
As per the Yii2 guide for conditional validation:
I think what you need to do is target each validation rule individually rather than trying to do them as a collective set. So in discussion terms (non code) the theory would be… check this current field and if this field and any of the other two associated fields are blank then you are required - else you can be blank.
You apply that rule to each of the fields so they all have the same set of rules as each other, if any of them break the rules then the form cannot be submitted - or if any one of them (or all of them) has a value then it’s ok for the form to be submitted.
In terms of the javascript client side validation I included that also for you, but you need to replace this part “multivalidationform” with the actual name of the form you created. This references the exact field id name of the form - it’s inside each of the three rules in the code below, so basically you need to replace it 3 x times.
Here is the code I wrote as an example for you:
/**
* @return array the validation rules.
*/
public function rules()
{
return [
['first_name', 'required', 'when' => function ($model) {
return (empty($model->first_name) && empty($model->last_name) && empty($model->orgname));
}, 'whenClient' => "function (attribute, value) {
return ($('#multivalidationform-first_name').val() == '' && $('#multivalidationform-last_name').val() == '' && $('#multivalidationform-orgname').val() == '');
}"],
['last_name', 'required', 'when' => function ($model) {
return (empty($model->first_name) && empty($model->last_name) && empty($model->orgname));
}, 'whenClient' => "function (attribute, value) {
return ($('#multivalidationform-first_name').val() == '' && $('#multivalidationform-last_name').val() == '' && $('#multivalidationform-orgname').val() == '');
}"],
['orgname', 'required', 'when' => function ($model) {
return (empty($model->first_name) && empty($model->last_name) && empty($model->orgname));
}, 'whenClient' => "function (attribute, value) {
return ($('#multivalidationform-first_name').val() == '' && $('#multivalidationform-last_name').val() == '' && $('#multivalidationform-orgname').val() == '');
}"]
];
}
I hope it works for you.
Edit: The name of your form is in your view file like so (without the hyphens):
<?php $form = ActiveForm::begin(['id' => 'multi-validation-form']); ?>
I called mine “multi-validation-form”, use your code inspector to see the name of the input id for each one.