Forums

Required field

Marizu 15 Apr, 2012
Hi, in the form i am building there are telephone and email fields. If you fill the telephone field you needn't fill the email field and viceversa. But one of them must be required. How can I do this?
Thanks!
GreyHead 16 Apr, 2012
Hi Marizu,

This seems to be quite tricky but I got a validation that works. Add this to a Load JS action on the ON Load event
function eitherOr(el){
  el.validation.erase('required');
  if ( !$('phone').value && !$('email').value ) {
    el.validation.push("required");
    el.errors.push("Enter either phone or email");
    return false;
  } else {
    return true;
  }
}
and change phone and email to match the ids of the two inputs.

Then add validate['%eitherOr'] in the Class box of each input.

Bob
GreyHead 24 Apr, 2012
Hi Tiago,

This was written for CFv4 and works OK as far as I know. What problem do you get? Are there any errors showing in the browser JavaScript console?

Bob
This topic is locked and no more replies can be posted.