You are here

function poll_choice_js in Drupal 6

Same name and namespace in other branches
  1. 7 modules/poll/poll.module \poll_choice_js()

Menu callback for AHAH additions.

1 string reference to 'poll_choice_js'
poll_menu in modules/poll/poll.module
Implementation of hook_menu().

File

modules/poll/poll.module, line 322
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_choice_js() {
  include_once 'modules/node/node.pages.inc';
  $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.
  $choice_form = $form['choice_wrapper']['choice'];
  unset($choice_form['#prefix'], $choice_form['#suffix']);

  // Prevent duplicate wrappers.
  $output = theme('status_messages') . drupal_render($choice_form);
  drupal_json(array(
    'status' => TRUE,
    'data' => $output,
  ));
}