Ive got a proper working module but if I use hook_forms() function it doens't insert the 'type' in the type field in the node table.

This is how my code looks:

preparing drupal_get_form

global $user;
$node=new stdClass();
echo $output;

my hook_forms function

if(strpos($form_id, 'my_node_type_form')===0){
return $forms;

I guess I have to add arguments to $forms array so it still know which node type its handling? I tried $forms[$form_id]=array('callback'=>'my_node_type_form', 'callback arguments'=>array('type'=>'my_node_type')) But its no use.


gInverted’s picture

To add to he previous post when using hook_forms() the hook_insert function is not even called. I just calls a core funciton to save the node but without the type.

mooffie’s picture

I don't know what you're trying to achieve.

Whatever, "the form function" doesn't equal "hook_form". These two are very different. Your hook_form is called by the real form function, which is implemented by Drupal and does quite a lot of things.

gInverted’s picture

Thanks for your time. Im aware of the hook_form(s) difference. I used hook_forms to map form_ids because I create a lot of forms from one builder function. Altough the form_ids are indeed correct mapped, the $forms return in hook_forms doesn't contain any node type data. And maybe it shouldn't. But after using the hook_forms function it is like the node builder function doesn't know what node type it is handling hence it gives a blank "" node type.

mooffie’s picture

Im aware of the hook_form(s) difference.

No, no. I was speaking of hook_form, not of hook_forms ;-)

When Drupal is asked to show a node form, the following happens:

  • Drupal calls node_form() to construct the form.
  • node_form() does a lot of things; for example, it adds the "Publishing options" fieldset, the "Submit" and "Delete" buttons, and a lot more. It *also* calls your module's hook_form() to add your own fields to the form. (I'm assuming your module is one providing a node type).

What you're trying to do is to replace Drupal's node_form() with your own function. You shouldn't do that because node_form() does quite a few things that are needed in order to make the node system work at all. You shouldn't touch these low-level things.

What are you trying to achieve? I'm not sure you've told us. In other words, what's the problem that drove you to do what you're doing?

gInverted’s picture

I indeed have a module which implements a node type. Which is populated by a node form (structured by hook_form). My intention is to display this form on a page. Ive no problem establishing that. But since I need multiple instances of the same form on this page I need to call hook_forms() to give unique ids to every form. Otherwise they will conflict with each other.

My problem is:

when using hook_forms() a forms variable is populated. Above called as $forms. When this $forms variable gets populated the form gets saved with all data except for the node type. So what you see in the node table is that every field is populated correctly except for the `type`field. This one stays blank.

Maybe I have to add something to the `callback arguments` in $forms. Just like there`s a callback value. Ive tried everything but I can`t see to get the node type through.

Hope you understand.

mooffie’s picture


This should be 'node_form', not 'my_node_type_form'. I explained why.

You shouldn't need to pass the node type as parameter. It's in the node object already, and Drupal sees it. (To be exact, it's node_form() that sees it, and if it equals 'my_node_type', it calls your my_node_type_form() to complete the form.)

(BTW, I once published code very similar to yours. The comment about ['#submit'] isn't relevant in your case.)

gInverted’s picture

That indeed solved the problem!

Ive nowhere found that information. I couldn't deduct that from the info in the documentation or on other tutorial websites.


However, now emerges a new obstacle. Hook_alter is not called. I used that function to unset the revision menu options et cetera.

Thank you very much.

gInverted’s picture

Posted too fast. The form_id is ofcourse changed. Have to alter my switch statement.

Again thanks for your enlightening answers.