summaryrefslogtreecommitdiff
path: root/modules/contact
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-10-09 15:39:12 +0000
committerDries Buytaert <dries@buytaert.net>2009-10-09 15:39:12 +0000
commita5dba069fb404bc0f2999bf2732154c75d5e4f2c (patch)
tree64923ba6b02449109cdd592c420c52fde4acef46 /modules/contact
parent0e98ff2018d765fe43bdd3f71e827601709ccd68 (diff)
downloadbrdo-a5dba069fb404bc0f2999bf2732154c75d5e4f2c.tar.gz
brdo-a5dba069fb404bc0f2999bf2732154c75d5e4f2c.tar.bz2
- #440876 by Dave Reid, sun: reuse comment.module's anonymous cookie information for contact forms.
Diffstat (limited to 'modules/contact')
-rw-r--r--modules/contact/contact.js15
-rw-r--r--modules/contact/contact.pages.inc12
2 files changed, 26 insertions, 1 deletions
diff --git a/modules/contact/contact.js b/modules/contact/contact.js
new file mode 100644
index 000000000..effac8145
--- /dev/null
+++ b/modules/contact/contact.js
@@ -0,0 +1,15 @@
+// $Id$
+(function ($) {
+
+Drupal.behaviors.contact = {
+ attach: function(context) {
+ $.each(['name', 'mail'], function () {
+ var cookie = $.cookie('Drupal.user.' + this);
+ if (cookie) {
+ $('#contact-site-form input[name=' + this + ']', context).once('comment').val(cookie);
+ }
+ });
+ }
+};
+
+})(jQuery);
diff --git a/modules/contact/contact.pages.inc b/modules/contact/contact.pages.inc
index d4a15bea5..5ad41d6f1 100644
--- a/modules/contact/contact.pages.inc
+++ b/modules/contact/contact.pages.inc
@@ -52,6 +52,11 @@ function contact_site_form($form, &$form_state) {
}
}
+ if (!$user->uid) {
+ $form['#attached']['library'][] = array('system', 'cookie');
+ $form['#attached']['js'][] = drupal_get_path('module', 'contact') . '/contact.js';
+ }
+
$form['#token'] = $user->uid ? $user->name . $user->mail : '';
$form['name'] = array(
'#type' => 'textfield',
@@ -117,10 +122,15 @@ function contact_site_form_validate($form, &$form_state) {
* Form submission handler for contact_site_form().
*/
function contact_site_form_submit($form, &$form_state) {
- global $language;
+ global $user, $language;
$values = $form_state['values'];
+ // Save the anonymous user information to a cookie for reuse.
+ if (!$user->uid) {
+ user_cookie_save($values);
+ }
+
// E-mail address of the sender: as the form field is a text field,
// all instances of \r and \n have been automatically stripped from it.
$from = $values['mail'];