You are here

function shoutbox_add_form in Shoutbox 6.2

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

Generates form for adding shouts.

2 string references to 'shoutbox_add_form'
shoutbox_rules_add_action in shoutbox_rules/shoutbox_rules.module
Adds a shout.
shoutbox_view in ./shoutbox.module
View the shoutbox

File

./shoutbox.module, line 343
Shout box 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() {
  global $user;
  $form = array();

  // Check permissions before showing input form
  if (!(_shoutbox_user_access('post shouts') || _shoutbox_user_access('post shouts without approval'))) {
    $form[] = array(
      '#type' => 'item',
      '#value' => theme('shoutbox_post_forbidden'),
    );
    return $form;
  }

  // If we're viewing a shoutbox page that is being paged, don't
  // show the form, because an ajax update won't make sense. Instead,
  // give a link back to the unpaged page
  if (arg(0) == 'shoutbox' && $_GET['page']) {
    return array(
      'shoutbox_return_link' => array(
        '#type' => 'item',
        // Use $_GET['q'] because the page might not be just 'shoutbox'
        '#value' => '« ' . l(t('Return to the shoutbox'), $_GET['q']),
      ),
    );
  }
  $max = variable_get('shoutbox_max_length', 255);
  $form['wrapper'] = array(
    '#type' => 'fieldset',
    '#collapsible' => FALSE,
  );

  // Placeholder for inline error messages
  $form['wrapper']['error_message'] = array(
    '#type' => 'item',
    '#value' => '<div id="shoutbox-error" class="error" title="Click to close"></div>',
  );

  // The shout field
  $form['wrapper']['message'] = array(
    '#type' => variable_get('shoutbox_widget_type', 'textfield'),
    '#size' => 15,
    '#maxlength' => $max ? $max : NULL,
  );

  // Placeholder for ajax throbber image
  $form['wrapper']['throbber'] = array(
    '#type' => 'item',
    '#value' => '<div id="shoutbox-throbber"></div>',
  );

  // The submit button
  $form['wrapper']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Shout'),
  );
  $int_msg = theme('shoutbox_interval_message', shoutbox_get_refresh_rate());
  if ($int_msg) {
    $form['wrapper']['interval_message'] = array(
      '#type' => 'item',
      '#value' => $int_msg,
    );
  }
  $form['js'] = array(
    '#type' => 'hidden',
    '#value' => 0,
  );
  $form['#prefix'] = '<div class="shoutbox-add-form">';
  $form['#suffix'] = '</div>';

  // Allow modules to alter the form
  shoutbox_invoke('form', $shout = NULL, $form);
  return $form;
}