You are here

function slack_validate_test_message in Slack 7

Validate if text or attachment for test message is not empty.

1 string reference to 'slack_validate_test_message'
slack_send_test_message_form in includes/pages/slack.pages.inc
Slack test message form.

File

includes/pages/slack.pages.inc, line 115
Slack module page functions.

Code

function slack_validate_test_message($form, &$form_state) {
  $message_is_empty = empty($form_state['values']['slack_test_message']);
  $attachment_enabled = $form_state['values']['slack_attachment_enabled'];

  // At least one of these fields must be filled to send message.
  $fields_to_check_in_attachments = array(
    'slack_test_pretext',
    'slack_test_attachment_text',
    'slack_test_footer',
  );
  $attachment_is_empty = TRUE;
  foreach ($fields_to_check_in_attachments as $field_to_check) {
    if (!empty($form_state['values'][$field_to_check])) {
      $attachment_is_empty = FALSE;
      break;
    }
  }
  if ($message_is_empty && (!$attachment_enabled || $attachment_is_empty)) {
    form_set_error('empty_message', t('Empty message and attachment text'));
  }
}