Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
can this be modifed so as to:
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
This should do it.