Saturday, November 27, 2010

<?php

function phptemplate_user_register($form) {

    $variables = array('user' => $user, 'form' => $form);

    return _phptemplate_callback('user_register', $variables);

}

?>
Then create a .tpl.php file with that name.
In this case, user_register.tpl.php
We can use this PHP snippet:
<?php

drupal_set_message('< pre >'. var_export($variables,TRUE) .'< /pre >');

?>
This provides us with the variable names (inside the $form variable) that are available to "drupal render" at your own chosen place.

* Tip: To preserve the functionality of Drupal's catch-all-remaining form elements, you must pass the the form values in from template.php in a broader variables array (as described above). This allows you to use a form variable with form element names as keys, rather than using form names directly. Form names directly will build the form, but without the ability to drupal_render all remaining form elements, and several hidden ones are essential to a functioning Drupal form.

Example of a form theming .tpl.php file:
<div id="regform1">

<fieldset class="group-account-basics collapsible"><legend>Account Basics</legend>
<?php print drupal_render($form['name']); ?>
<?php print drupal_render($form['mail']); ?>
<?php print drupal_render($form['pass']); ?>
<?php print drupal_render($form['field_user_picture']); ?>
<?php print drupal_render($form['field_city']); ?>
</fieldset>

</div>
<div id="regform2">

<fieldset class="group-story collapsible"><legend>My Story</legend>
<?php print drupal_render($form['field_storypic']); ?>
<?php print drupal_render($form['field_user_story_field']); ?>
</fieldset>

</div>
<?php print drupal_render($form['captcha']); ?>
<?php print drupal_render($form['submit']); ?>
<?php

unset($form['field_mostimportantlesson']);

print drupal_render($form);

?>