You are hereDrupal contact form inupt size

Drupal contact form inupt size


By mehow - Posted on 31 August 2011

I recently struggled with changing default input size of a Drupal contact form fields. First I tried with hook_form_alter.

I built a simple module with just one function:

function custom_contact_form_alter(&$form, $form_state, $form_id) {
switch($form_id) {
case 'contact_mail_page':
// customizations go here
$form['mail']['#size'] = 30;
break;
}
}

but it did not work. I could change the #maxsize attribute but not the #size. So I went back to doc page and read it carefully. Last line was crucial: "After all module hook implementations are invoked, the hook_form_alter() implementations from themes are invoked in the same manner."

I opened up my theme template.php file and there it was, right at the bottom. hook_theme registering template for a contact page:

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

and custom_contact_mail_page($form):

function custom_contact_mail_page($form) {
/* If the visitor types contact/quote or contact/info,
otherwise the default template is used, ie: contact-mail-page */
$form['mail']['#size'] = 24;
$form['mail']['#title'] = t('Email address');

$output = drupal_render($form['subject']);
return $output . drupal_render($form);
}

All I had to do was to change the #size value. Theming the contact form in Drupal 6 page from Caroline Schnapp describes all the details nicely.

Tags