Skip to main content

Drupal 7

With Drupal 7, it is pretty simple to add forms anywhere you can call PHP code using drupal_get_form(). Getting a personal contact form to print, however, is a bit more complicated. And not well documented. drupal_get_form() tells us a unique form instructor requires an object is passed as an argument, but does not really say how. Examining drupal_get_form(), one will notice function_get_args() is called.

On a couple occasions I found it necessary to generate and save a file from within a module or theme. The last time it was to create a custom stylesheet based on values from theme settings, so I'll use that in my example on how you can do the same. The first thing to do, of course, is to alter the system theme settings form with your custom fields using hook_form_system_theme_settings_alter(). We'll create one field to change the background color of the body and add a custom submit handler to take care generating the custom stylesheet.