Community Documentation

Adding markup to form elements

Last updated June 8, 2008. Created by Steven Jones on June 8, 2008.
Log in to edit this page.

Form API provides an easy way to add arbitrary html immediately before or after a specific form element. You do so like this:

<?php
$form
['form_item'] = array(
 
'#type' => 'textfield',
 
'#title' => t('My Form Item'),
 
'#prefix' => '<a name="my_form_item"></a>', // Add markup before form item
);
?>

and

<?php
$form
['form_item'] = array(
 
'#type' => 'textfield',
 
'#title' => t('My Form Item'),
 
'#suffix' => '<hr />', // Add markup after form item
);
?>

Warning

While this approach works, and can be useful please note that it mixes content and design. The Form API array describes the structure of the form, and the visual look of the form should be handled by theme functions. See the section on theming for details of how to add markup to your forms properly.

nobody click here