Index: feedback.css =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feedback/feedback.css,v retrieving revision 1.7 diff -u -p -r1.7 feedback.css --- feedback.css 15 Jan 2011 07:13:13 -0000 1.7 +++ feedback.css 15 Jan 2011 12:28:07 -0000 @@ -1,12 +1,14 @@ /* $Id: feedback.css,v 1.7 2011/01/15 07:13:13 sun Exp $ */ +/** + * Styles for the feedback form. + */ /* Reset commonly set styles */ #block-feedback-form, #block-feedback-form .feedback-link, #block-feedback-form .feedback-link *, #block-feedback-form .content, -#block-feedback-form form, -#block-feedback-form form label { +#block-feedback-form form { float: none; margin: 0; padding: 0; @@ -16,7 +18,6 @@ color: inherit; } - #block-feedback-form { display: none; position: fixed; @@ -43,31 +44,30 @@ padding: 6px; background-color: #fff; opacity: 0.9; - max-width: 220px; + max-width: 300px; } /* IE6 doesn't support max-width. */ * html #block-feedback-form form { - width: 220px; + width: 300px; } #block-feedback-form .feedback-help { margin: 0 0 0.5em; font-size: 10px; line-height: normal; } -#block-feedback-form .feedback-submitted { - margin-top: 0.2em; - font-size: 10px; -} #block-feedback-form .feedback-message { height: 10ex; } -#block-feedback-form #feedback-throbber { - height: 20px; -} -#block-feedback-form .throbbing { - background: url(images/throbber.gif) no-repeat left center; +#block-feedback-form .ajax-progress .throbber { + background: transparent url(images/throbber.gif) no-repeat left center; + height: 16px; + width: 16px; } -#block-feedback-form #feedback-submit { - background-color: #fff; - margin: 0; + +/** + * Styles for existing feedback messages. + */ +#block-feedback-form .feedback-submitted { + margin-top: 0.2em; + font-size: 10px; } Index: feedback.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feedback/feedback.js,v retrieving revision 1.7 diff -u -p -r1.7 feedback.js --- feedback.js 12 Nov 2010 01:26:01 -0000 1.7 +++ feedback.js 15 Jan 2011 12:13:19 -0000 @@ -31,22 +31,33 @@ Drupal.behaviors.feedbackForm = { Drupal.feedbackFormToggle($block, true); } ); - $block.find('form').hide() - .find(':input[name="ajax"]').val(1).end() - .submit(function() { - // Toggle throbber/button. - $('#feedback-throbber', this).addClass('throbbing'); - $('#feedback-submit', this).fadeOut('fast', function () { - Drupal.feedbackFormSubmit($(this).parents('form')); - }); - return false; - }); + $block.find('form').hide(); $block.show(); }); } }; /** + * Re-collapse the feedback form after every successful form submission. + */ +Drupal.behaviors.feedbackFormSubmit = { + attach: function (context) { + var $context = $(context); + if (!$context.is('#feedback-status-message')) { + return; + } + // Collapse the form. + $('#block-feedback-form .feedback-link').click(); + // Blend out and remove status message. + window.setTimeout(function () { + $context.fadeOut('slow', function () { + $context.remove(); + }); + }, 3000); + } +}; + +/** * Collapse or uncollapse the feedback form block. */ Drupal.feedbackFormToggle = function ($block, enable) { @@ -59,27 +70,4 @@ Drupal.feedbackFormToggle = function ($b } }; -/** - * Collapse or uncollapse the feedback form block. - */ -Drupal.feedbackFormSubmit = function ($form) { - $.post($form.get(0).action, $form.serialize(), function (data) { - // Collapse the form. - $('#block-feedback-form').find('.feedback-link').click(); - // Display status message. - $form.parent().parent().append('
' + data.message + '
'); - // Reset form values. - $(':input[name="message"]', $form).val(''); - $('#feedback-throbber', $form).removeClass('throbbing'); - $('#feedback-submit', $form).show(); - // Blend out status message. - window.setTimeout(function () { - $('#feedback-status-message').fadeOut('slow', function () { - $(this).remove(); - }); - }, 3000); - }, 'json'); - return false; -}; - -})(jQuery) +})(jQuery); Index: feedback.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/feedback/feedback.module,v retrieving revision 1.82 diff -u -p -r1.82 feedback.module --- feedback.module 15 Jan 2011 06:42:37 -0000 1.82 +++ feedback.module 15 Jan 2011 12:37:19 -0000 @@ -116,8 +116,6 @@ function feedback_form($form, &$form_sta // Store the path on which this form is displayed. $form['location'] = array('#type' => 'value', '#value' => $_GET['q']); - // Allow the form to be submitted via AJAX. - $form['ajax'] = array('#type' => 'hidden', '#default_value' => 0); $form['help'] = array( '#prefix' => '
', @@ -152,12 +150,24 @@ function feedback_form($form, &$form_sta '#required' => TRUE, '#wysiwyg' => FALSE, ); - $form['submit'] = array( + $form['actions'] = array( + '#type' => 'actions', + // Without clearfix, the AJAX throbber wraps in an ugly way. + // @todo Patch #type actions in core? + '#attributes' => array('class' => array('clearfix')), + ); + $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Send'), + '#value' => t('Send feedback'), '#id' => 'feedback-submit', - '#prefix' => '
', - '#suffix' => '
', + '#ajax' => array( + 'wrapper' => 'feedback-form', + 'callback' => 'feedback_form_ajax_callback', + 'progress' => array( + 'type' => 'throbber', + 'message' => '', + ), + ), ); return $form; @@ -171,14 +181,47 @@ function feedback_form_submit($form, &$f $entry->message = $form_state['values']['message']; $entry->location = $form_state['values']['location']; feedback_save($entry); - $message = t('Thanks for your feedback!'); - if ($form_state['values']['ajax']) { - drupal_json_output(array('message' => $message)); - exit; - } - else { - drupal_set_message($message); + + drupal_set_message(t('Thanks for your feedback!')); +} + +/** + * AJAX callback for feedback_form() submissions. + */ +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('
', $messages['status']); + $html = '
' . $messages . '
'; + $build['#commands'][] = ajax_command_append('#block-feedback-form', $html); + return $build; } /**