Index: modules/comment/comment.js =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.js,v retrieving revision 1.12 diff -u -p -r1.12 comment.js --- modules/comment/comment.js 31 Aug 2009 05:51:08 -0000 1.12 +++ modules/comment/comment.js 6 Oct 2009 21:14:02 -0000 @@ -4,7 +4,7 @@ Drupal.behaviors.comment = { attach: function (context, settings) { $.each(['name', 'homepage', 'mail'], function () { - var cookie = Drupal.comment.getCookie('comment_info_' + this); + var cookie = $.cookie('Drupal.user.' + this); if (cookie) { $('#comment-form input[name=' + this + ']', context).once('comment').val(cookie); } @@ -12,25 +12,4 @@ Drupal.behaviors.comment = { } }; -Drupal.comment = {}; - -Drupal.comment.getCookie = function (name) { - var search = name + '='; - var returnValue = ''; - - if (document.cookie.length > 0) { - offset = document.cookie.indexOf(search); - if (offset != -1) { - offset += search.length; - var end = document.cookie.indexOf(';', offset); - if (end == -1) { - end = document.cookie.length; - } - returnValue = decodeURIComponent(document.cookie.substring(offset, end).replace(/\+/g, '%20')); - } - } - - return returnValue; -}; - })(jQuery); Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.775 diff -u -p -r1.775 comment.module --- modules/comment/comment.module 29 Sep 2009 15:31:14 -0000 1.775 +++ modules/comment/comment.module 6 Oct 2009 21:14:02 -0000 @@ -1623,6 +1623,7 @@ function comment_form($form, &$form_stat $node = node_load($comment->nid); if (!$user->uid && variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) != COMMENT_ANONYMOUS_MAYNOT_CONTACT) { + $form_state['#attached']['js'][] = array('data' => 'misc/jquery.cookie.js', 'weight' => JS_LIBRARY + 2); $form_state['#attached']['js'][] = drupal_get_path('module', 'comment') . '/comment.js'; } @@ -1947,7 +1948,7 @@ function comment_form_validate($form, &$ foreach (array('name', 'homepage', 'mail') as $field) { // Set cookie for 365 days. if (isset($form_state['values'][$field])) { - setcookie('comment_info_' . $field, $form_state['values'][$field], REQUEST_TIME + 31536000, '/'); + setcookie('Drupal.user.' . $field, $form_state['values'][$field], REQUEST_TIME + 31536000, '/'); } } } @@ -2100,12 +2101,12 @@ function template_preprocess_comment(&$v $variables['signature'] = $comment->signature; $variables['title'] = l($comment->subject, 'comment/' . $comment->cid, array('fragment' => "comment-$comment->cid")); $variables['template_files'][] = 'comment-' . $variables['node']->type; - + // Helpful $content variable for templates. foreach (element_children($variables['elements']) as $key) { $variables['content'][$key] = $variables['elements'][$key]; } - + // Set status to a string representation of comment->status. if (isset($comment->in_preview)) { $variables['status'] = 'comment-preview'; @@ -2429,4 +2430,3 @@ function comment_filter_format_delete($f ->condition('format', $format->format) ->execute(); } - Index: modules/contact/contact.js =================================================================== RCS file: modules/contact/contact.js diff -N modules/contact/contact.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/contact/contact.js 6 Oct 2009 21:14:02 -0000 @@ -0,0 +1,16 @@ +// $Id$ +(function ($) { + +Drupal.behaviors.contact = { + attach: function(context) { + $.each(['name', 'mail'], function () { + var cookie = $.cookie('Drupal.user.' + this); + alert(cookie); + if (cookie) { + $('#contact-site-form input[name=' + this + ']', context).once('comment').val(cookie); + } + }); + } +}; + +})(jQuery); Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.26 diff -u -p -r1.26 contact.pages.inc --- modules/contact/contact.pages.inc 29 Sep 2009 15:31:14 -0000 1.26 +++ modules/contact/contact.pages.inc 6 Oct 2009 21:14:02 -0000 @@ -32,7 +32,7 @@ function contact_site_page() { /** * Form builder; the site-wide contact form. */ -function contact_site_form() { +function contact_site_form($form, &$form_state) { global $user; $categories = db_query("SELECT cid, category FROM {contact} ORDER BY weight, category")->fetchAllKeyed(); @@ -49,6 +49,11 @@ function contact_site_form() { } } + if (!$user->uid) { + $form['#attached']['js'][] = array('data' => 'misc/jquery.cookie.js', 'weight' => JS_LIBRARY + 2); + $form['#attached']['js'][] = drupal_get_path('module', 'contact') . '/contact.js'; + } + $form['#token'] = $user->uid ? $user->name . $user->mail : ''; $form['name'] = array( '#type' => 'textfield', @@ -102,12 +107,22 @@ function contact_site_form() { * Form validation handler for contact_site_form(). */ function contact_site_form_validate($form, &$form_state) { + global $user; + if (!$form_state['values']['cid']) { form_set_error('cid', t('You must select a valid category.')); } if (!valid_email_address($form_state['values']['mail'])) { form_set_error('mail', t('You must enter a valid e-mail address.')); } + if (!$user->uid) { + foreach (array('name', 'mail') as $field) { + // Set cookie for 365 days. + if (isset($form_state['values'][$field])) { + setcookie('Drupal.user.' . $field, $form_state['values'][$field], REQUEST_TIME + 31536000, '/'); + } + } + } } /**