You are here

function boxes_form_submit in Boxes 7.2

Submit function for box form

1 string reference to 'boxes_form_submit'
boxes_form in includes/boxes.pages.inc
Boxes form

File

includes/boxes.pages.inc, line 281
Box Functions

Code

function boxes_form_submit($form, &$form_state) {
  $box = boxes_form_submit_build_box($form, $form_state);
  $box
    ->setValues($form_state['values']);
  $insert = $box
    ->internalIdentifier();
  field_attach_submit('box', $box, $form, $form_state);
  $box
    ->save();
  $watchdog_args = array(
    '@type' => $box
      ->typeName(),
    '%title' => $box
      ->label(),
  );
  $t_args = array(
    '@type' => $box
      ->typeName(),
    '%title' => $box
      ->label(),
  );
  if ($insert) {
    watchdog('boxes', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $box
      ->viewURL());
    drupal_set_message(t('@type %title has been created.', $t_args));
  }
  else {
    watchdog('boxes', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $box
      ->viewURL());
    drupal_set_message(t('@type %title has been updated.', $t_args));
  }
  if ($box
    ->identifier()) {
    $form_state['redirect'] = $box
      ->viewURL();
  }
  else {

    // In the unlikely case something went wrong on save, the box will be
    // rebuilt and box form redisplayed the same way as in preview.
    drupal_set_message(t('The block could not be saved.'), 'error');
    $form_state['rebuild'] = TRUE;
  }
}