I have written my own module for example called: calc and i have used module_load_include('inc', 'calc', 'form.inc') in my calc.module file, and placed form.inc file inside my module's directory: calc/form.inc but it doesn't see that file. What am I doing wrong?

I am using Drupal 6.


It should be:

module_load_include('inc', 'calc', 'form');

(The 'inc' in the first argument automagically appends as the extension)


With module_load_include('inc', 'calc', 'form.inc') you are including the form.inc.inc file present in the directory where the calc.module file is present.

If you want to include the form.inc file in that directory, you need to use module_load_include('inc', 'calc', 'form'), as Jimajamma said.

The first argument of module_load_include() is $type, the second is $module, and the third is $name. They are concatenated together using the following code.

$file = './' . drupal_get_path('module', $module) . "/$name.$type";

When you don't pass $name to the function, it will use for $name the same value passed for $module.

You could also include a relative path in $name, such as 'includes/form'; in that case the loaded file would be 'includes/form.inc', where includes is a directory contained in the directory containing the module whose name is passed as second argument.

  • Thanks, I was just testing if (module_load_include('inc', 'calc', 'form')) { print 'included'; }, and it was giving me nothing, but then I tried if (module_load_include('inc', 'calc', 'form') !== FALSE {print 'it worked!'; }. – Alexander Kim Aug 12 '12 at 4:33
  • That's right: The function returns FALSE only when the file to include is not found, or it is a directory; when the file exists, it returns nothing. – kiamlaluno Aug 12 '12 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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