contact_site_form
function contact_site_form
contact_site_form($form, &$form_state)
Form constructor for the site-wide contact form.
See also
Related topics
File
- modules/contact/contact.pages.inc, line 15
- Page callbacks for the Contact module.
Code
function contact_site_form($form, &$form_state) { global $user; // Check if flood control has been activated for sending e-mails. $limit = variable_get('contact_threshold_limit', 5); $window = variable_get('contact_threshold_window', 3600); if (!flood_is_allowed('contact', $limit, $window) && !user_access('administer contact forms')) { drupal_set_message(t("You cannot send more than %limit messages in @interval. Try again later.", array('%limit' => $limit, '@interval' => format_interval($window))), 'error'); drupal_access_denied(); drupal_exit(); } // Get an array of the categories and the current default category. $categories = db_select('contact', 'c') ->addTag('translatable') ->fields('c', array('cid', 'category')) ->orderBy('weight') ->orderBy('category') ->execute() ->fetchAllKeyed(); $default_category = db_query("SELECT cid FROM {contact} WHERE selected = 1")->fetchField(); // If there are no categories, do not display the form. if (!$categories) { if (user_access('administer contact forms')) { drupal_set_message(t('The contact form has not been configured. <a href="drupal_7-modules-contact-contact-pages-inc-function-contact_site_form-@add">Add one or more categories<-a> to the form-', array('@add' => url('admin-structure-contact-add'))), 'error'); } else { drupal_not_found(); drupal_exit(); } } -- If there is more than one category available and no default category has -- been selected, prepend a default placeholder value- if (!$default_category) { if (count($categories) > 1) { $categories = array(0 => t('- Please choose -')) + $categories; } else { $default_category = key($categories); } } if (!$user->uid) { $form['.html?lang=en#attached']['library'][] = array('system', 'jquery.cookie'); $form['.html?lang=en#attributes']['class'][] = 'user-info-from-cookie'; } $form['.html?lang=en#attributes']['class'][] = 'contact-form'; $form['name'] = array( '.html?lang=en#type' => 'textfield', '.html?lang=en#title' => t('Your name'), '.html?lang=en#maxlength' => 255, '.html?lang=en#default_value' => $user->uid ? format_username($user) : '', '.html?lang=en#required' => TRUE, ); $form['mail'] = array( '.html?lang=en#type' => 'textfield', '.html?lang=en#title' => t('Your e-mail address'), '.html?lang=en#maxlength' => 255, '.html?lang=en#default_value' => $user->uid ? $user->mail : '', '.html?lang=en#required' => TRUE, ); $form['subject'] = array( '.html?lang=en#type' => 'textfield', '.html?lang=en#title' => t('Subject'), '.html?lang=en#maxlength' => 255, '.html?lang=en#required' => TRUE, ); $form['cid'] = array( '.html?lang=en#type' => 'select', '.html?lang=en#title' => t('Category'), '.html?lang=en#default_value' => $default_category, '.html?lang=en#options' => $categories, '.html?lang=en#required' => TRUE, '.html?lang=en#access' => count($categories) > 1, ); $form['message'] = array( '.html?lang=en#type' => 'textarea', '.html?lang=en#title' => t('Message'), '.html?lang=en#required' => TRUE, ); // We do not allow anonymous users to send themselves a copy // because it can be abused to spam people. $form['copy'] = array( '.html?lang=en#type' => 'checkbox', '.html?lang=en#title' => t('Send yourself a copy.'), '.html?lang=en#access' => $user->uid, ); $form['actions'] = array('.html?lang=en#type' => 'actions'); $form['actions']['submit'] = array( '.html?lang=en#type' => 'submit', '.html?lang=en#value' => t('Send message'), ); return $form; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!contact!contact.pages.inc/function/contact_site_form/7.x