function contact_mail_page in Drupal 6
Same name and namespace in other branches
- 4 modules/contact.module \contact_mail_page()
- 5 modules/contact/contact.module \contact_mail_page()
1 string reference to 'contact_mail_page'
- contact_site_page in modules/
contact/ contact.pages.inc - Site-wide contact page.
File
- modules/
contact/ contact.pages.inc, line 25 - User page callbacks for the contact module.
Code
function contact_mail_page() {
global $user;
$form = $categories = array();
$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->uid ? $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)) {
$default_category = t('- Please choose -');
$categories = array(
$default_category,
) + $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.'),
);
}
else {
$form['copy'] = array(
'#type' => 'value',
'#value' => FALSE,
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send e-mail'),
);
}
else {
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;
}