You are here

function shoutbox_add_form_validate in Shoutbox 7.2

Same name and namespace in other branches
  1. 5 shoutbox.module \shoutbox_add_form_validate()
  2. 6.2 shoutbox.module \shoutbox_add_form_validate()
  3. 6 shoutbox.module \shoutbox_add_form_validate()
  4. 7 shoutbox.module \shoutbox_add_form_validate()

Makes sure uses don't submit default values.

Parameters

$form_id: The form ID of the form.

$form_values: Form values.

File

./shoutbox.module, line 724
Shoutbox module displays a block for users to create short messages for the whole site. Uses AHAH to update the database and display content.

Code

function shoutbox_add_form_validate($form, &$form_state) {

  // Remove trailing whitespace.
  $form_state['values']['message'] = trim($form_state['values']['message']);
  $form_state['values']['nick'] = trim($form_state['values']['nick']);
  $max = variable_get('shoutbox_max_length', 255);
  $bErrorFound = false;

  // Empty nickname.
  if (!$form_state['values']['nick'] || $form_state['values']['nick'] == t(DEFAULTNICK)) {
    form_set_error('nick', t('You must enter a nickname.'));
    $bErrorFound = true;
  }

  // Empty message.
  if (!$form_state['values']['message'] || $form_state['values']['message'] == t(DEFAULTMSGTEXT)) {
    form_set_error('message', t('You must enter a message.'));
    $bErrorFound = true;
  }
  elseif ($max && strlen(utf8_decode($form_state['values']['message'])) > $max) {
    form_set_error('message', t('Your ' . DEFAULTSHOUTSINGULAR . ' is too long. Only @max characters are allowed.', array(
      '@max' => $max,
    )));
    $bErrorFound = true;
  }

  // Check user's permission and set message.
  if (!$bErrorFound && !_shoutbox_user_access('post shouts without approval')) {
    drupal_set_message(t('Your ' . DEFAULTSHOUTSINGULAR . ' is waiting for approval by a moderator.'), 'warning');
  }
}