A Warning - Mind Warp ahead This blog serves as in intermediary blog - a place where my ideas go to stew and mature (and sometimes die). For a more distilled reading of business and technical content please visit my company blog at http://marlindigitalagency.com

Wednesday, December 30, 2009

The Quest for a Thank You Message from Drupal's Webform Module

There is a way to send out a thank you message using the advanced php processing that drupal forms currently has:


$to = $form['submitted']['email']['#value'];
$from = variable_get('site_mail', '');
$body = drupal_html_to_text($node->webform['confirmation']);
$message = drupal_mail('webform_extra', 'reply', $to, language_default(), array('body' => $body), $from, TRUE);

function webform_extra_mail($key, &$message, $params) {
$message['subject'] = "Thanks for your interest.";
$message['body'] = $params['body'];

This is all well and good - however it is not very user friendly - here is what I propose:

Add an Auto-responder or Thank you Message in the Web-mail settings.
We need to collect the following data:
  • The field that will be used when sending the thank you message
  • The email Subject
  • The email Body
We will also need the remaining fields to be tokenized as well as having the other site information available.

All I want to accomplish here is when a user fills out a form they receive a thank you message

My approach is to build a custom module called 'webform_autoresponder'

____________________________________________________
My info file:

webform_autoresponder.info
***********************************************************************
; $Id: $
name = Webform AutoResonder
description = Enables Webforms to have a configurable Email Autoresponder field
core = 6.x

Right now I my schema will look something like this

____________________________________
NID / From / Subject / Message /
____________________________________

For the module itself I am using hook form alter to insert my fields where I would like them in the already existing webform edit form:


/**
* Implementation of hook_form_alter().
* Change the way an existing form is rendered
*/
function webform_autoresponder_form_webform_node_form_alter(&$form, &$form_state){
$form['webform']['mail_settings']['ar_from'] = array(
'#type' => 'textfield',
'#title' => t('From'),
'#description' => t('If you create a conditional email recipient based off a field this is the address that it will be emailed from'),
'#default_value' => 'confemail',
);
$form['webform']['mail_settings']['ar_subject'] = array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#description' => t('If you create a conditional email recipient based off a field this is the subject that will be in the email to them'),
);
$form['webform']['mail_settings']['ar_confemail'] = array(
'#type' => 'textarea',
'#title' => t('Confirmation Email message'),
'#description' => t('If you create a conditional email recipient based off a field this is the body that will be emailed to them'),
'#default_value' => 'confemail',
'#cols' => 40,
'#rows' => 10,
);
}
Naturally as this module becomes more mature I will post more code and eventually commit it to the Drupal repository. Please leave any advise or suggestions

-Robert

No comments:

Post a Comment

Followers

About Me

My photo
I help people relate to other people better :) Preferring harmony over conflict I have been helping people relate better with one another since I was a kiddo.