This code makes it so that a user must fill out one of two possible fields.

// Grab variables.
$email = $form_values['submitted_tree']['email_address'];
$phone = $form_values['submitted_tree']['phone_number'];

// Check for values.
if ($email == "" && $phone == "") {
  form_set_error('submitted][email_address', t('E-mail Addresses or Phone Number must be given.'));
  form_set_error('submitted][phone_number', '');
}

Requires that an email or phone number is given.

Comments

verres’s picture

I'm looking for a way to do something similar...but that would require that ONE and ONLY ONE of two fields on a cck node be filled out. Meaning: if they enter a value into one of the fields, they CANNOT enter a value into the other.

if they entered values in both fields...an error message would appear -- indicating that only field 1 OR field 2 could have a value in it.

-C

ps. I would have used a checkbox -- but the two fields in consideration are both auto-complete node reference fields... and I can't have a user selecting both!
-c

mikeytown2’s picture

// Grab variables.
$email = $form_values['submitted_tree']['email_address'];
$phone = $form_values['submitted_tree']['phone_number'];

// Check for values.
if (empty($email) && empty($phone)) {
  form_set_error('submitted][email_address', t('E-mail Addresses or Phone Number must be given.'));
  form_set_error('submitted][phone_number', '');
}
if (!empty($email) && !empty($phone)) {
  form_set_error('submitted][email_address', t('E-mail Addresses or Phone Number must be given.'));
  form_set_error('submitted][phone_number', '');
}