You are here

function shoutbox_add_form_submit in Shoutbox 7

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

Handles submission of a shout.

Handles both ajax submission and regular form submission.

File

./shoutbox.module, line 690
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_submit($form, &$form_state) {
  global $user;

  // Check user's permission and set shout visibility status accordingly.
  if (!_shoutbox_user_access('post shouts without approval')) {
    $moderate = 1;
  }
  else {
    $moderate = 0;
  }

  // Build the shout object.
  $shout = new stdClass();
  $shout->uid = $user->uid;

  //$shout->nick = $user->name ? $user->name : variable_get('anonymous', 'Anonymous');
  $shout->nick = $form_state['values']['nick'] ? $form_state['values']['nick'] : variable_get('anonymous', 'Anonymous');
  $shout->shout = $form_state['values']['message'];
  $shout->moderate = $moderate;
  $shout->created = REQUEST_TIME;
  $shout->changed = $shout->created;
  $shout->sid = session_id();
  $shout->module = 'shoutbox';

  // Allow other modules to make changes to the shout.
  $a1 = NULL;
  shoutbox_invoke('presave', $shout, $a1, $form_state);

  // Add shout to the database.
  drupal_write_record('shoutbox', $shout);

  // Alert other modules about the new shout via hook.
  shoutbox_invoke('insert', $shout, $a1, $form_state);
  return;
}