Using Drupal 7, I have a content type that uses the email field module(CCK) so that the page author can enter an email address for readers to mail them. With display suite module together with views contact form module, the saved page displays the site wide contact form. The emailed responses are delivered to the email address that was entered by the content author. That works great.
I wanted to add extra fields and managed to do this with the code below which I added to the template.php file but the code only works with the site wide contact form on example.com/contact
My question: How can I add those fields to the email field module's contact form as well?
This is the code I'm using to include the fields in the contact form display:
function MYTHEME_form_alter( &$form, &$form_state, $form_id ) {
if( $form_id == 'contact_site_form' ){
$form['message']['#weight'] = 6;
$form['copy']['#weight'] = 7;
$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#required' => TRUE,
'#weight' => 4
);
$form['province'] = array(
'#type' => 'textfield',
'#title' => t('Province'),
'#required' => TRUE,
'#weight' => 5
);
}
}
This is the code I'm using to include the field responses in the email that gets delivered:
function MYTHEME_mail_alter(&$message) {
if ($message['id'] == 'contact_page_mail' ||
$message['id'] == 'contact_page_autoreply') {
$message['body'][2] = t('My Phone Number') . ': "' . $message['params'][phone'] . '"';
$message['body'][3] = t('My Province') . ': "' . $message['params'] ['province'] . '"';
}
}