Drupal Form Theming Quick Tip

Very quickly, here's a useful tip if you're theming any kind of Drupal form. Just put the following in your overriding .tpl.php file

<?php print "<pre>"; print_r(array_values($form));print "</pre>"; ?>

and it'll output a complete list of things you can theme.
Not ground breaking I know, but one of those things I can never seem to find when I want!

5 comments

1
soxofaanOctober 12th 2007 @ 03:47PM

with the devel module (http://drupal.org/project/devel) enabled it can be even as easy as "dvm($form)"

2
Nate HaugOctober 12th 2007 @ 07:45PM

Or if you want to take it further and get ALL variables available within any of your .tpl.php file:

<pre><?php print_r(get_defined_vars()); ?></pre>

3
LaurenceOctober 12th 2007 @ 10:48PM

Thanks guys, excellent suggestions!

4
ppOctober 13th 2007 @ 03:14PM

I use this:

<?php
drupal_set_message
('<pre>'.print_r(array_values($form),true).'</pre>');
?>

5
GuestJuly 23rd 2008 @ 09:17PM

var_dump ;)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options