You are here

function push_notifications_mass_push_form_validate in Push Notifications 7

Validation handler for sending out a mass-push notification.

File

includes/push_notifications.admin.inc, line 467
Admin files for Push Notifications module.

Code

function push_notifications_mass_push_form_validate($form, &$form_state) {
  $recipients = $form_state['values']['recipients'];

  // Define an empty array for the payload.
  $payload = array();

  // Add all "message" elements to the payload.
  // Other modules can alter the contents of the payload
  // array by adding additional elements to 'message'
  // when it implements hook_form_alter.
  $message_elements = $form_state['values']['message'];
  foreach ($message_elements as $key => $value) {
    $payload[$key] = $value;
  }

  // Store payload in the form_state.
  $form_state['values']['payload'] = $payload;

  // Make sure at least one recipient (group) is selected.
  if (empty($recipients['ios']) && empty($recipients['android'])) {
    form_set_error('recipients', t('No message was sent. Please select at least one recipient group.'));
  }

  // Validate that the message size is ok.
  if (!push_notifications_check_payload_size($form_state['values']['payload'])) {
    form_set_error('message', t('Your message exceeds the allowed size of !max_size bytes. Please shorten your message.', array(
      '!max_size' => PUSH_NOTIFICATIONS_APNS_PAYLOAD_SIZE_LIMIT,
    )));
  }
}