views:

31

answers:

3

I need to display some custom HTML/Processing code before a Drupal form can be shown. How do I return both the custom HTML and the form? The code I have is:

function myfunction() {
    global $base_path, $base_url;
    $output = ""; // Clear the variable, just in case
    include ('includes/SOME_HTML_OUTPUT.inc');
    return $output; //NOT GOING TO WORK
    return drupal_get_form('my_form');
}
A: 

what does the drupal_get_form() function output? just html?

you could do this: return $output.drupal_get_form('my_form');

????

Thomas Clayson
This will actually work, but is a fundamentally wrong way of doing this with Drupal.
googletorp
A: 

please clarify your question.

do *includes/SOME_HTML_OUTPUT.inc* should produce $output ? where does *includes/SOME_HTML_OUTPUT.inc* exactly placed?

and take a look at module_load_include API. it might help.

takpar
+3  A: 

The proper way to do what you want is:

function myfunction() {
  $output = theme('your_theme_function'); // Create your custom markup.
  $output .= drupal_get_form('my_form'); // Create the form markup.
  return $output;
}

Your theme function should handle the creating your custom markup. It can be done with a php function or using a template and a preprocess function.

The pretty thing the above approach is that you hook into the Drupal theming system and gain it's flexibility. If a designer wants to change the HTML, he can do that like he normally would do. You also gain the ability to add template suggestions and other nice when you use the Drupal theming system.

In your specific case you might know that you want need all of this good stuff, that Drupal provides, but you should still make it a habit to code like this. It'll make your modules more flexible. Also should you ever want to contribute something back in form of a module on drupal.org, coding like this is an absolute must, if you want your module to be usable by others.

googletorp
As usual your answers are very thorough and detailed. Thank You.
jini

related questions