You are here

function shorten_save_js in Shorten URLs 6

Same name and namespace in other branches
  1. 8.2 shorten.module \shorten_save_js()
  2. 8 shorten.module \shorten_save_js()
  3. 7.2 shorten.module \shorten_save_js()
  4. 7 shorten.module \shorten_save_js()

JS callback for submitting the Shorten form.

1 string reference to 'shorten_save_js'
shorten_menu in ./shorten.module
Implementation of hook_menu().

File

./shorten.module, line 503
Shortens URLs via external services.

Code

function shorten_save_js() {
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];
  $form = form_get_cache($form_build_id, $form_state);
  $form_state['post'] = $form['#post'] = $_POST;
  $form['#programmed'] = $form['#redirect'] = FALSE;
  $args = $form['#parameters'];

  //This happens if someone goes directly to the JS processing page.
  if (!is_array($args) && !$args) {
    drupal_goto('shorten');
    watchdog('shorten', 'Someone tried to access the JavaScript processing page for the Shorten module directly.', array(), WATCHDOG_DEBUG);
    return;
  }
  $form_id = array_shift($args);
  drupal_process_form($form_id, $form, $form_state);
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  //Get HTML for the replacement form. Only these elements will be AHAH-refreshed.
  $step = $form_state['storage']['step'];
  $new_form['shortened_url_' . $step] = $form['shortened_url_' . $step];
  $new_form['url_' . $step] = $form['url_' . $step];

  //If the $form['save']['#ahah']['wrapper'] div was found in a #prefix or #suffix of a form element that we re-rendered here,

  //then we would have to unset() it to prevent duplicate wrappers. However, we have a somewhat unique implementation in which the wrappers

  //are actually their own elements, so this is not an issue.
  $output = theme('status_messages') . drupal_render($new_form);

  //Return the results.
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}