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.
<?php
/**
* In this example, the form asks how a client prefers to be contacted.
* Whatever they choose is then checked to be sure the matching
* field has the information needed to respond in the preferred manner.
*/
// Get form values
$phone = $form_values['submitted_tree']['phone'];
$fax= $form_values['submitted_tree']['fax'];
$email = $form_values['submitted_tree']['email'];
$preferred = $form_values['submitted_tree']['preferred_contact_method'];
// If Preferred is set to Phone, check that they entered a phone number.
if ($phone == "" && $preferred == 'Phone') {
form_set_error('submitted][phone', t('If you really prefer to be contacted by phone, please include a phone number.'));
}
// If Preferred is set to Fax, check that they entered a fax number.
if ($fax== "" && $preferred == 'Fax') {
form_set_error('submitted][fax', t('If you really prefer to be contacted by fax, please include a fax number.'));
}
// If Preferred is set to Email, check that they entered an email address.
if ($email == "" && $preferred == 'Email') {
form_set_error('submitted][email', t('If you really prefer to be contacted by email, please include an email address.'));
}
?>