You are here

function feedback_form_ajax_callback in Feedback 7.2

AJAX callback for feedback_form() submissions.

1 string reference to 'feedback_form_ajax_callback'
feedback_form in ./feedback.module
Form constructor for the feedback form.

File

./feedback.module, line 443
Allows site visitors and users to report issues about this site.

Code

function feedback_form_ajax_callback($form, &$form_state) {

  // If there was a form validation error, re-render the entire form.
  if (!$form_state['executed']) {
    return $form;
  }

  // Otherwise, return a fresh copy of the form, so the user may post additional
  // feedback.
  // Reset the static cache of drupal_html_id().
  // @see drupal_process_form()
  // @see drupal_html_id()
  $seen_ids =& drupal_static('drupal_html_id');
  $seen_ids = array();

  // Prevent the form from being processed again.
  // @see drupal_build_form()
  list($form, $new_form_state) = ajax_get_form();
  $new_form_state['input'] = array();
  drupal_process_form($form['#form_id'], $form, $new_form_state);

  // Return AJAX commands in order to output the special success message.
  // @see ajax_deliver()
  $build = array(
    '#type' => 'ajax',
  );
  $html = drupal_render($form);
  $build['#commands'][] = ajax_command_insert(NULL, $html);

  // A successful form submission normally means that there were no errors, so
  // we only render status messages.
  $messages = drupal_get_messages();
  $messages += array(
    'status' => array(),
  );
  $messages = implode('<br />', $messages['status']);
  $html = '<div id="feedback-status-message">' . $messages . '</div>';
  $build['#commands'][] = ajax_command_append('#block-feedback-form', $html);
  return $build;
}