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']);
}
Opensource, CMS, PHP, MySql, Drupal, Frameworks
Friday, February 11, 2011
Implement Drupal Autocomplete
Menu
function custom_menu(){
$items = array();
$items['custom/article'] = array(
'title' => t('Hello'),
'page callback' => 'article_load',
'access callback' => 'user_access',
'access arguments' => array('access user profiles'),
'type' => MENU_CALLBACK,
);
return $items;
}
Form
$form['article'] = array(
'#type' => 'textfield',
'#title' => t('Article Title'),
'#description' => t('Known article'),
'#default_value' => $form['_account']['#value']->article,
'#autocomplete_path' => 'custom/article',
);
function article_load($string = '') {
$matches = array();
if ($string) {
$result = db_query_range("SELECT nid, title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')", $string, 0, 10);
while ($user = db_fetch_object($result)) {
$matches[$user->title] = check_plain($user->title);
}
}
drupal_json($matches);
}
function custom_menu(){
$items = array();
$items['custom/article'] = array(
'title' => t('Hello'),
'page callback' => 'article_load',
'access callback' => 'user_access',
'access arguments' => array('access user profiles'),
'type' => MENU_CALLBACK,
);
return $items;
}
Form
$form['article'] = array(
'#type' => 'textfield',
'#title' => t('Article Title'),
'#description' => t('Known article'),
'#default_value' => $form['_account']['#value']->article,
'#autocomplete_path' => 'custom/article',
);
function article_load($string = '') {
$matches = array();
if ($string) {
$result = db_query_range("SELECT nid, title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')", $string, 0, 10);
while ($user = db_fetch_object($result)) {
$matches[$user->title] = check_plain($user->title);
}
}
drupal_json($matches);
}
Subscribe to:
Posts (Atom)