Adding markup to form elements
Last modified: June 8, 2008 - 08:14
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.
