function contact_mail_page in Drupal 5
Same name and namespace in other branches
- 4 modules/contact.module \contact_mail_page()
- 6 modules/contact/contact.pages.inc \contact_mail_page()
1 string reference to 'contact_mail_page'
- contact_site_page in modules/
contact/ contact.module - Site-wide contact page
File
- modules/
contact/ contact.module, line 417 - Enables the use of personal and site-wide contact forms.
Code
function contact_mail_page() {
global $user;
$result = db_query('SELECT cid, category, selected FROM {contact} ORDER BY weight, category');
while ($category = db_fetch_object($result)) {
$categories[$category->cid] = $category->category;
if ($category->selected) {
$default_category = $category->cid;
}
}
if (count($categories) > 0) {
$form['#token'] = $user->name . $user->mail;
$form['contact_information'] = array(
'#value' => filter_xss_admin(variable_get('contact_form_information', t('You can leave a message using the contact form below.'))),
);
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('Your name'),
'#maxlength' => 255,
'#default_value' => $user->uid ? $user->name : '',
'#required' => TRUE,
);
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('Your e-mail address'),
'#maxlength' => 255,
'#default_value' => $user->uid ? $user->mail : '',
'#required' => TRUE,
);
$form['subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 255,
'#required' => TRUE,
);
if (count($categories) > 1) {
// If there is more than one category available and no default category has been selected,
// prepend a default placeholder value.
if (!isset($default_category)) {
$categories = array(
t('--'),
) + $categories;
}
$form['cid'] = array(
'#type' => 'select',
'#title' => t('Category'),
'#default_value' => $default_category,
'#options' => $categories,
'#required' => TRUE,
);
}
else {
// If there is only one category, store its cid.
$category_keys = array_keys($categories);
$form['cid'] = array(
'#type' => 'value',
'#value' => array_shift($category_keys),
);
}
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
'#required' => TRUE,
);
// We do not allow anonymous users to send themselves a copy
// because it can be abused to spam people.
if ($user->uid) {
$form['copy'] = array(
'#type' => 'checkbox',
'#title' => t('Send yourself a copy.'),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send e-mail'),
);
}
else {
$form['#error'] = array(
'#value' => t('The contact form has not been configured.'),
);
}
return $form;
}