Even if this module is mainly for anonymous users, we use it in some content types for both: anonymous and authorized users. In case of authorized users it would be nice to auto fill name and e-Mail like in the normal contact form. The attached Patch added this functionality.

Comments

bobsomebody’s picture

I was just about to post up a patch request about something similar to this. Except my patch is rather crude and sloppy.

simply find this code in the anonymous_contact.module

function anonymous_contact_page($account) {
  if (FALSE == $account) {
    $output = t('No user was found with that ID');
  }
  elseif (!valid_email_address($account->mail)) {
    $output = t('Unfortunately !name has not provided a valid e-mail address.  This means we would be unable to deliver any e-mail to them.', array('!name' => $account->name));
  }
  elseif (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
    $output = t('You cannot contact more than %number members per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));
  }
  else {
    drupal_set_title(check_plain(t('Contact !name', array('!name' => $account->name))));
    $output = drupal_get_form('anonymous_contact_form', $account);
  }
  return $output;
}

and replace it with this code here:

function anonymous_contact_page($account) {
  global $user;
  if($user->uid != 0){
    header("location: /user/".$account->uid."/contact"); 
  }
  if (FALSE == $account) {
    $output = t('No user was found with that ID');
  }
  elseif (!valid_email_address($account->mail)) {
    $output = t('Unfortunately !name has not provided a valid e-mail address.  This means we would be unable to deliver any e-mail to them.', array('!name' => $account->name));
  }
  elseif (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
    $output = t('You cannot contact more than %number members per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));
  }
  else {
    drupal_set_title(check_plain(t('Contact !name', array('!name' => $account->name))));
    $output = drupal_get_form('anonymous_contact_form', $account);
  }
  return $output;
}

This will simply redirect the user to the regular contact forms if they are currently logged into the site.

I am sure there is a much cleaner way to do this but the idea is simple, if $user->uid != 0 (not anonymous user id) then use regular contact form. Maybe someone could come up with a cleaner patch?

On a side note some way to get this module picked up by pathauto would be awesome also :)

MiniMax’s picture

StatusFileSize
new904 bytes

My first patch was buggy, use this one please.