if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('contact_hourly_threshold', 3)));
}
else {
$output = drupal_get_form('contact_mail_page');
}
return $output;
}
function contact_mail_page() {
global $user;
$form = $categories = array();
$result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
$form['contact_information'] = array('#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))));
drupal_set_message(t('The contact form has not been configured. <a href="@add">Add one or more categories</a> to the form.', array('@add' => url('admin/build/contact/add'))), 'error');
}
return $form;
}
/**
* Validate the site-wide contact page form submission.
*/
function contact_mail_page_validate($form, &$form_state) {
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.'));
}
}
/**
* Process the site-wide contact page form submission.
*/
function contact_mail_page_submit($form, &$form_state) {
global $language;
$values = $form_state['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'];
// Load category properties and save form values for email composition.
$contact = contact_load($values['cid']);
$values['contact'] = $contact;
// Send the e-mail to the recipients using the site default language.
watchdog('mail', '%name-from sent an e-mail regarding %category.', array('%name-from' => $values['name'] ." [$from]", '%category' => $contact['category']));
drupal_set_message(t('Your message has been sent.'));
// Jump to home page rather than back to contact page to avoid
// contradictory messages if flood control has been activated.
$form_state['redirect'] = '';
}
/**
* Personal contact page.
*/
function contact_user_page($account) {
global $user;
if (!valid_email_address($user->mail)) {
$output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit")));
}
else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
$output = t('You cannot contact more than %number users per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));