Commit 1a692854 authored by Matthias Hutterer's avatar Matthias Hutterer
Browse files

#269747: fixes sending of mails through the contact form

parent 1dc403cc
...@@ -255,7 +255,7 @@ function email_menu() { ...@@ -255,7 +255,7 @@ function email_menu() {
/** /**
* The contact form page. * The contact form page.
*/ */
function email_mail_page($nid, $fieldname) { function email_mail_page($nid, $field_name) {
if (!is_numeric($nid)) { if (!is_numeric($nid)) {
drupal_not_found(); drupal_not_found();
return; return;
...@@ -265,13 +265,16 @@ function email_mail_page($nid, $fieldname) { ...@@ -265,13 +265,16 @@ function email_mail_page($nid, $fieldname) {
drupal_not_found(); drupal_not_found();
return; return;
} }
$field = $node->$field_name;
$email = $field[0]['email'];
$types = content_types($node->type); $types = content_types($node->type);
// Validate field name // Validate field name
$types = content_types($node->type); $types = content_types($node->type);
if (!isset($types['fields'][$fieldname]) || if (empty($email) ||
$types['fields'][$fieldname]['type'] != 'email' || !isset($types['fields'][$field_name]) ||
($types['fields'][$fieldname]['display_settings']['teaser']['format'] != 'contact' && $types['fields'][$field_name]['type'] != 'email' ||
$types['fields'][$fieldname]['display_settings']['full']['format'] != 'contact')) { ($types['fields'][$field_name]['display_settings']['teaser']['format'] != 'contact' &&
$types['fields'][$field_name]['display_settings']['full']['format'] != 'contact')) {
drupal_not_found(); drupal_not_found();
return; return;
} }
...@@ -281,7 +284,7 @@ function email_mail_page($nid, $fieldname) { ...@@ -281,7 +284,7 @@ function email_mail_page($nid, $fieldname) {
$output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('email_hourly_threshold', 3))); $output = t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('email_hourly_threshold', 3)));
} }
else { else {
$output = drupal_get_form('email_mail_page_form', $node, $field); $output = drupal_get_form('email_mail_page_form', $node, $field_name, $email);
} }
return $output; return $output;
...@@ -290,18 +293,21 @@ function email_mail_page($nid, $fieldname) { ...@@ -290,18 +293,21 @@ function email_mail_page($nid, $fieldname) {
/** /**
* Contact form * Contact form
*/ */
function email_mail_page_form($form_state, $node, $field) { function email_mail_page_form($form_state, $node, $field_name, $email) {
global $user; global $user;
$form['node'] = array( $form['node'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $node, '#value' => $node,
); );
$form['field'] = array( $form['field_name'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $field, '#value' => $field_name,
);
$form['email'] = array(
'#type' => 'value',
'#value' => $email,
); );
$form['name'] = array( $form['name'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => t('Your name'), '#title' => t('Your name'),
...@@ -354,10 +360,9 @@ function email_mail_page_form_validate($form, &$form_state) { ...@@ -354,10 +360,9 @@ function email_mail_page_form_validate($form, &$form_state) {
*/ */
function email_mail_page_form_submit($form, &$form_state) { function email_mail_page_form_submit($form, &$form_state) {
$node = $form_state['values']['node']; $node = $form_state['values']['node'];
$field = $form_state['values']['field']; $field_name = $form_state['values']['field_name'];
$email = $field[0]['email']; $email = $form_state['values']['email'];
$types = content_types($node->type);
// E-mail address of the sender: as the form field is a text field, // E-mail address of the sender: as the form field is a text field,
// all instances of \r and \n have been automatically stripped from it. // all instances of \r and \n have been automatically stripped from it.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment