CreatingI have actually never needed to use a template file for a form.
As far as I can see, Drupal core code uses theme functions, when a form, or part of a form needs to be rendered in a particular way; a theme function that calls drupal_render() is normally enough for any purposes.
To reply to the question, creating a template file for a form is not different from creating a template file that is not for a form.
Define a theme function, using as theme function the name of the form builder callback. The code should be similar to the following:
/**
* Implementation of hook_theme().
*/
function mymodule_theme() {
return array(
'mymodule_form' => array(
'template' => 'mymodule-form',
'file' => 'mymodule.admin.inc',
'arguments' => array('form' => NULL),
),
);
}
If the form contains the value $form['field_1']
, its value will be available in the template file as $field_1
. The template file will be also able to use any values passed from template_preprocess_mymodule_form()
.
I have actually never needed to use a template file for a form.
As far as I can see, Drupal core code uses theme functions, when a form, or part of a form needs to be rendered in a particular way; a theme function that calls drupal_render() is normally enough for any purposes.