View source
<?php
function views_contact_form_contact_form($form, &$form_state, $data) {
if (db_table_exists('contact')) {
$count = db_select('contact', 'contact')
->fields('contact')
->execute()
->rowCount();
if ($count == 0) {
drupal_set_message(t('Views Contact Form module is disabled because no contact category
is found. To get this module working properly,
the <a href="@modulepage">contact module from core</a> needs to be
enabled and at least <a href="@contactpage">one category must
exist</a>.
If you don\'t want the module contact, just enable it, disable it,
but don\'t uninstall it.', array(
'@modulepage' => url('admin/modules'),
'@contactpage' => url('admin/structure/contact'),
)), 'warning');
return array();
}
}
else {
drupal_set_message(t('Views Contact Form module is disabled because the contact
table doesn\'t exists. To get this module working properly,
the <a href="@modulepage">contact module from core</a> needs to be
enabled and at least <a href="@contactpage">one category must
exist</a>.
If you don\'t want the contact module from core, just enable it,
disable it, but don\'t uninstall it.', array(
'@modulepage' => url('admin/modules'),
'@contactpage' => url('admin/structure/contact'),
)), 'warning');
return array();
}
module_load_include('inc', 'contact', 'contact.pages');
$form = drupal_retrieve_form('contact_site_form', $form_state);
if (isset($form['cid'])) {
unset($form['cid']);
}
$form['to'] = array(
'#type' => 'value',
'#value' => $data,
);
return $form;
}
function views_contact_form_contact_form_validate($form, &$form_state) {
if (!valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t('You must enter a valid e-mail address.'));
}
}
function views_contact_form_contact_form_submit($form, &$form_state) {
global $user, $language;
$values = $form_state['values'];
$values['sender'] = $user;
$values['sender']->name = $values['name'];
$values['sender']->mail = $values['mail'];
$emails = $values['to'];
if (!$user->uid) {
user_cookie_save(array_intersect_key($values, array_flip(array(
'name',
'mail',
))));
}
$from = $values['sender']->mail;
foreach ($emails['emails'] as $email) {
drupal_mail('views_contact_form', 'views_contact_form_page_mail', $email, language_default(), $values, $from);
if ($values['copy']) {
drupal_mail('views_contact_form', 'views_contact_form_page_copy', $from, $language, $values, $from);
}
watchdog('mail', '%sender-name (@sender-from) sent an e-mail.', array(
'%sender-name' => $values['name'],
'@sender-from' => $from,
));
}
flood_register_event('views_contact_form', variable_get('contact_threshold_window', 3600));
drupal_set_message(t('Your message has been sent.'));
}