I have an external form that needs to be loaded inside a template file, used by a block. Right now, i'm a bit confused as to how to load this .inc. Looking at the API docs point to module_load_include() which I've tried with no luck (see example 1, from the template file):

module_load_include('inc', 'example2'); 
print(render(drupal_get_form("example2_form"))); //Form method in inc file is called "example2_form();

The actual form method is just a few settings for now, once I prove this works...

function example2_form($form, $form_state) {
  $form['fname'] = array(
    '#type' => 'textfield',
    "#attributes" => array(
      'placeholder' => t("First Name"),

  $form['#validate'][] = "example2_form_validate";
  $form['#submit'][] = "example2_form_submit";

  return $form;

I figure the cleanest approach (besides figuring out what could cause the .inc to not load here) is to just drop the form code into the .module, and load the Form array in the blocks hook_block_view(). However, I like to keep stuff clean, so if there's something I'm overlooking here, or how to best do this, it would be cool to know.

File name for the form include is example2.form.inc.

  • Just for clarification:1) what is your module name? In your module_load_include() sample, you give it as example2_form, but in your form method you show has the same name...these can't both be right. 2) Is your function ever called by other code? Generally, you need to call a function returning a form from somewhere else, like e.g. hook_menu() etc.
    – bhotel
    Dec 23, 2014 at 21:12
  • Whoops. Didn't catch that. I've updated that to reference the module, example2. Dec 23, 2014 at 22:14

2 Answers 2


Module_load_include includes the file with extension and filename. Sinds your file is called example2.form.inc and you include the file example2.inc, it doesn't work.

You should be using

Module_load_include('inc', 'example2.form'); 

The syntax for module_load_include is

module_load_include('suffix', 'module', 'file_without_suffix');

Files can be loaded in module.info via the files[] array but this should be for classes or interface files. enter link description here

If you want to load a form into a template manually, then yes define the block and hook_block_view($delta) will need to load the form include file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.