Index: modules/contact.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact.module,v
retrieving revision 1.19
diff -u -r1.19 contact.module
--- modules/contact.module 31 Jul 2005 10:12:47 -0000 1.19
+++ modules/contact.module 31 Jul 2005 16:30:05 -0000
@@ -7,7 +7,7 @@
*/
// Users are not allowed to send more than x mails/hour:
-define('CONTACT_HOURLY_THRESHOLD', 3);
+define('CONTACT_HOURLY_THRESHOLD', 300);
/**
* Implementation of hook_help().
@@ -58,7 +58,22 @@
* Implementation of hook_settings().
*/
function contact_settings() {
- return form_textarea(t('Additional information'), 'contact_form_information', variable_get('contact_form_information', t('You can leave us a message using the contact form below.')), 60, 5, t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact'))));
+ $group = form_textarea(t('Additional information'), 'contact_form_information', variable_get('contact_form_information', t('You can leave us a message using the contact form below.')), 60, 5, t('Information to show on the contact page. Can be anything from submission guidelines to your postal address or telephone number.', array('%form' => url('contact'))));
+
+ $rows = array(array(form_checkbox(t('Name'), 'contact_field_name', 1, 1, NULL, array('disabled' => 'disabled')), form_checkbox(t('Required'), 'contact_field_name_required', 1, variable_get('contact_field_name_required', 1))),
+ array(form_checkbox(t('E-mail'), 'contact_field_mail', 1, variable_get('contact_field_mail', 1)), form_checkbox(t('Required'), 'contact_field_mail_required', 1, variable_get('contact_field_mail_required', 1))),
+ array(form_checkbox(t('Phone number'), 'contact_field_phone', 1, variable_get('contact_field_phone', 0)), form_checkbox(t('Required'), 'contact_field_phone_required', 1, variable_get('contact_field_phone_required', 0))),
+ array(form_checkbox(t('Postal address'), 'contact_field_postal', 1, variable_get('contact_field_postal', 0)), form_checkbox(t('Required'), 'contact_field_postal_required', 1, variable_get('contact_field_postal_required', 0))),
+ array(array('data' => form_checkbox(t('Category'), 'contact_field_category', 1, 1, t('It\'s just shown if there is more than one category.'), array('disabled' => 'disabled')), 'colspan' => 2)),
+ array(form_checkbox(t('Subject'), 'contact_field_subject', 1, variable_get('contact_field_subject', 1)), form_checkbox(t('Required'), 'contact_field_subject_required', 1, variable_get('contact_field_subject_required', 0))),
+ array(form_checkbox(t('Message'), 'contact_field_message', 1, 1, NULL, array('disabled' => 'disabled')), form_checkbox(t('Required'), 'contact_field_message_required', 1, variable_get('contact_field_message_required', 1)))
+ );
+ $group3 = theme_table(array(), $rows);
+ $group2 = form_group(t("Fields to include on the contact form:"), $group3);
+
+ $group .= form_group_collapsible(t('Advanced Settings'), $group2, TRUE);
+ $output = form_group(t('Site-wide contact form'), $group, t('This settings just affects the side-wide contact form.', array('%contact' => url('contact'))));
+ return $output;
}
/**
@@ -95,6 +110,11 @@
$edit = $_POST['edit'];
if ($edit) {
+ // Remove whitespaces at the beginning and the end
+ foreach($edit as $key => $field) {
+ $edit[$key] = trim($field);
+ }
+
// Validate the message:
if (!$edit['message']) {
form_set_error('message', t('You must enter a message.'));
@@ -230,17 +250,22 @@
}
if ($edit) {
+ // Remove whitespaces at the beginning and the end
+ foreach($edit as $key => $field) {
+ $edit[$key] = trim($field);
+ }
+
// Validate the fields:
- if (!$edit['name']) {
+ if (!$edit['name'] && variable_get('contact_field_name_required', "1")) {
form_set_error('name', t('You must enter a name.'));
}
- if (!$edit['mail'] || !valid_email_address($edit['mail'])) {
+ if ((!$edit['mail'] || !valid_email_address($edit['mail'])) && variable_get('contact_field_mail_required', 1) && variable_get('contact_field_mail', 1)) {
form_set_error('mail', t('You must enter a valid e-mail address.'));
}
- if (!$edit['subject']) {
+ if (!$edit['subject'] && variable_get('contact_field_subject_required', 0) && variable_get('contact_field_subject', 1)) {
form_set_error('subject', t('You must enter a subject.'));
}
- if (!$edit['message']) {
+ if (!$edit['message'] && variable_get('contact_field_message_required', 1)) {
form_set_error('message', t('You must enter a message.'));
}
if (!$edit['category']) {
@@ -261,7 +286,39 @@
// Compose the body:
$message[] = t("%name sent a message using the contact form at %form:", array('%name' => $edit['name'], '%form' => url($_GET['q'], NULL, NULL, TRUE)));
- $message[] = $edit['message'];
+ $message[] = '';
+ $message[] = t("Contact information").':';
+ $message[] = '--------------------------------------------';
+ if ($edit['name']) {
+ $message[] = ' * '.t("Name") .':';
+ $message[] = $edit['name'];
+ }
+ if ($edit['mail']) {
+ $message[] = ' * '.t("E-mail address") .':';
+ $message[] = $edit['mail'];
+ }
+ if ($edit['phone']) {
+ $message[] = ' * '.t("Phone number") .':';
+ $message[] = $edit['phone'];
+ }
+ if ($edit['postal']) {
+ $message[] = ' * '.t("Postal address") .':';
+ $message[] = $edit['postal'];
+ }
+ $message[] = '';
+ if ($edit['message'] && $edit['subject'])
+ {
+ $message[] = t("Message: %subject", array('%subject' => $edit['subject']));
+ if ($edit['message']) {
+ $message[] = '--------------------------------------------';
+ $message[] = $edit['message'];
+ $message[] = '';
+ }
+ }
+ $message[] = '--------------------------------------------';
+ if ($edit['referrer']) {
+ $message[] = t("%name was reffered from: %referrer", array('%name' => $edit['name'], '%referrer' => $edit['referrer']));
+ }
// Tidy up the body:
foreach ($message as $key => $value) {
@@ -269,10 +326,10 @@
}
// Format the category:
- $subject = '['. $edit['category'] .'] '. $edit['subject'];
+ $subject = '['. variable_get('site_name', 'drupal') .'] ['. $edit['category'] .'] '. $edit['subject'];
// Prepare the body:
- $body = implode("\n\n", $message);
+ $body = implode("\n", $message);
// Load the category information:
$contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE category = '%s'", $edit['category']));
@@ -296,9 +353,12 @@
drupal_goto('contact');
}
}
- else if ($user->uid) {
- $edit['name'] = $user->name;
- $edit['mail'] = $user->mail;
+ else {
+ if ($user->uid) {
+ $edit['name'] = $user->name;
+ $edit['mail'] = $user->mail;
+ }
+ $edit['referrer'] = $_SERVER[HTTP_REFERER];
}
$result = db_query('SELECT category FROM {contact} ORDER BY category');
@@ -309,14 +369,25 @@
if (count($categories) > 1) {
$output = variable_get('contact_form_information', t('You can leave us a message using the contact form below.'));
- $output .= form_textfield(t('Your name'), 'name', $edit['name'], 60, 255, NULL, NULL, TRUE);
- $output .= form_textfield(t('Your e-mail address'), 'mail', $edit['mail'], 60, 255, NULL, NULL, TRUE);
- $output .= form_textfield(t('Subject'), 'subject', $edit['subject'], 60, 255, NULL, NULL, TRUE);
+ $output .= form_textfield(t('Your name'), 'name', $edit['name'], 60, 255, NULL, NULL, variable_get('contact_field_name_required', "1"));
+ if (variable_get('contact_field_mail', 1)) {
+ $output .= form_textfield(t('Your e-mail address'), 'mail', $edit['mail'], 60, 255, NULL, NULL, variable_get('contact_field_mail_required', 1));
+ }
+ if (variable_get('contact_field_phone', 0)) {
+ $output .= form_textfield(t('Your phone number'), 'phone', $edit['phone'], 60, 255, NULL, NULL, variable_get('contact_field_phone_required', 0));
+ }
+ if (variable_get('contact_field_postal', 0)) {
+ $output .= form_textarea(t('Your postal address'), 'postal', $edit['postal'], 60, 2, NULL, NULL, variable_get('contact_field_postal_required', 0));
+ }
+ if (variable_get('contact_field_subject', 1)) {
+ $output .= form_textfield(t('Subject'), 'subject', $edit['subject'], 60, 255, NULL, NULL, variable_get('contact_field_subject_required', 0));
+ }
if (count($categories) > 2) {
$output .= form_select(t('Category'), 'category', $edit['category'], $categories, NULL, NULL, NULL, TRUE);
}
- $output .= form_textarea(t('Message'), 'message', $edit['message'], 60, 5, NULL, NULL, TRUE);
+ $output .= form_textarea(t('Message'), 'message', $edit['message'], 60, 5, NULL, NULL, variable_get('contact_field_message_required', 1));
$output .= form_submit(t('Send e-mail'));
+ $output .= form_hidden('referrer', $edit['referrer']);
$output = form($output);
}
else {