Opensource, CMS, PHP, MySql, Drupal, Frameworks

Friday, February 11, 2011

Switch Contact form template In Drupal

step 1: call template

function garland_theme(){
return array(
'contact_mail_page' => array(
'arguments' => array('form' => NULL),
'template' => 'contact-mail-page',
),
);
}

step 2: create template files
contact-mail-page-info.tpl.php
contact-mail-page-quote.tpl.php

print $form_markup;

step 3: Create Preprocess Function
function garland_preprocess_contact_mail_page(&$vars){
switch(arg(1)){
case 'quote':
$vars['form']['name']['#title'] = t('Name');
$vars['form']['message']['#title'] = t('What you need');
$vars['template_file'] = 'contact-mail-page-quote';
break;
case 'info':
$vars['form']['message']['#title'] = t('what info you need??');
$vars['template_file'] = 'contact-mail-page-info';
break;
}

$vars['form_markup'] = drupal_render($vars['form']);
}