You are here

function workbench_email_form_validate in Workbench Email 7

Same name and namespace in other branches
  1. 7.3 workbench_email.admin.inc \workbench_email_form_validate()

Validates the form values.

Validates if the user has entered a valid subject / message for the emails.

Parameters

array $form: The form array

array $form_state: The form_state array

File

./workbench_email.admin.inc, line 111
Administrative forms for Workbench Email Module.

Code

function workbench_email_form_validate($form, &$form_state) {
  $workbench_emails = workbench_email_get();
  foreach ($workbench_emails as $transition_label => $email_transition_set) {
    foreach ($email_transition_set as $rid => $email_transition) {
      if (isset($form_state['values'][$transition_label])) {

        // Determine if subject is set with no message.
        if ($form_state['values'][$transition_label][$rid]['subject'] != NULL && $form_state['values'][$transition_label][$rid]['message'] == NULL) {
          form_set_error("{$transition_label}][{$rid}][message", t('You must add an email message if a subject is provided'));
        }

        // Determine if message is set with no subject.
        if ($form_state['values'][$transition_label][$rid]['subject'] == NULL && $form_state['values'][$transition_label][$rid]['message'] != NULL) {
          form_set_error("{$transition_label}][{$rid}][subject", t('You must add a subject if an email message is provided'));
        }
      }
    }
  }
}