Brightonart Ltd.
P.O. Box 3416
Brighton BN50 9HQ
Remove the name and email cookies from the Drupal 7 core contact form
Submitted by marcus on Tue, 30/10/2012 - 10:39
in
The contact module in Drupal 7 core uses a pair of cookies to pre-fill name and email in the form for returning users. Since the change in legislation around user details in cookies a lot of site owners will not want these cookies to be set.
Since editing core is a cardinal sin a good way to prevent the server setting these cookies is to add a submit hook for the contact form in a form alter in your own module.
/** * Implements hook_form_FORM_ID_alter(). */ function module_name_form_contact_site_form_alter(&$form, &$form_state, $form_id) { $form['#submit'][] = '_module_name_contact_personal_form_submit'; } /** * Additional form submission handler for contact_personal_form(). * * Remove the cookies set by the form for autofilling user details. * * @see contact_personal_form_submit() */ function _module_name_contact_personal_form_submit($form, &$form_state) { user_cookie_delete('name'); user_cookie_delete('mail'); }