[SOLVED] Conditional Rules Validation

I have a text input and a dropdown that represent the same thing but in different ways. I need to add a validation rule that checks to see if both fields are empty and if so displays a message stating that one or the other cannot be blank.

In my rules I currently have:




array('fieldx, fieldy', 'required'),



  1. How do I do this so that the default error box at the top of the form has a message like "Field X or Field Y cannot be blank". I tried using the "message" parameter but that makes whatever message I specify appear twice.

Thanks,

You should write your own validation function.

in rules:


array('fieldx', 'myRequired'),

and then write your function:




public function myRequired()

{

    if (($this->fieldx==null)&&($this->fieldy==null))

       $this->addError([...] );

}



Thanks, I still had to add an "addError" statement for both fields, but leaving one of the messages blank prevented the message from showing up twice at the top in the default error box.