You are here

function values_form_js in Values 6

Same name and namespace in other branches
  1. 7 values.module \values_form_js()

Menu callback for AHAH additions.

1 string reference to 'values_form_js'
values_menu in ./values.module
Implementation of hook_menu().

File

./values.module, line 246
API for managing reusable value sets.

Code

function values_form_js() {
  $form_state = array(
    'storage' => NULL,
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // Get the form from the cache.
  $form = form_get_cache($form_build_id, $form_state);
  $args = $form['#parameters'];
  $form_id = array_shift($args);

  // We will run some of the submit handlers so we need to disable redirecting.
  $form['#redirect'] = FALSE;

  // We need to process the form, prepare for that by setting a few internals
  // variables.
  $form['#post'] = $_POST;
  $form['#programmed'] = FALSE;
  $form_state['post'] = $_POST;

  // Build, validate and if possible, submit the form.
  drupal_process_form($form_id, $form, $form_state);

  // This call recreates the form relying solely on the form_state that the
  // drupal_process_form set up.
  $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);

  // Render the new output.
  $values_form = $form['values_wrapper']['data'];

  // Prevent duplicate wrappers.
  unset($values_form['#prefix'], $values_form['#suffix']);
  $output = theme('status_messages') . drupal_render($values_form);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}