I'd like to create a new node type with one addtional field of data. I've added the field to my database, but can't seem to save new data to it.

Here's what I've done so far:
Added the field name to the $fields[] in node_save().
Added the form textfield to the output from mymodule_form()
entered some test data into the field using sql.
succesfully displayed the new data using my module.

But when I post new content, and complete this new field, it doesn't seem to save it to the db.

I know this is a newbie question, but have a bruise on my head from banging it on the monitor all night, and thought I'd ask for help before needing hospitalization.

Thanks in advance,
- joe

PS. the documentation for developers is really coming along. I can't believe how much I'm learning about drupal now. Thanks

Comments

Dries’s picture

This is not exaclty a newbie question. Anyway, you'll want to implement a "mymodule_insert()", a "mymodule_update()" and a "mymodule_delete()" function, and possibly want to fiddle with a "mymodule_save()" hook. See the page module in CVS for a good example.

Also, make sure to read http://natrak.net/node.php?id=71.

Please help extend the documentation. It is people like you, learning the system, that can tell what documentation is lacking, and that can help fill the blanks. We rely on you ...

Anonymous’s picture

Thanks Dries,
I'm trying those hooks as well. Unfortunately, since they are not yet documented, I'm just looking for how they are used in other modules. I get the feeling there is a bigger picture that I don't see.

A process flow would help a lot.

Here are a few specific questions :
- Is it a bad idea to add a field to the node table? should I instead create a new table for my module?
- It seems I have to tell drupal when to call mymodule_update() because it doesn't seem to call it on its own.
- can i leave node.module alone? or will i have to make changes to it as well?

Thanks,
- Joe

moshe weitzman’s picture

- Is it a bad idea to add a field to the node table? should I instead create a new table for my module?
- It seems I have to tell drupal when to call mymodule_update() because it doesn't seem to call it on its own.
- can i leave node.module alone? or will i have to make changes to it as well?

1. yes, that is currently a bad idea. not terrible, but bad becasue you are straying from the designed ways

2. Update hook is called automatically by the node module after you edit an existing node. When you add a new node, the Insert hook is called automatically. These exist so that you may add/edit data in your module specific table(s)

3. You should need not need to change node.module

In general, a debugger helps a LOT when doing PHP development. If you are already an expert, you can get by without it. For the newbie/intermediate developer, it is a godsend.

joe lombardo’s picture

your pointers really helped and I was able to complete that task. Now I am trying to do the same thing and found myself stuck.

In the _form hook, I added the following:

$output .= form_textfield(t("new word"), "word", $edit["word"], 64, 64);

As instructed somewhere else in this forum. It didn't work. Than I searched for this bit of advice and saw in the page.module that they approached it differently:
$output .= form_textfield(t("new word"), "word", $node->word, 64, 64);

So my question is, when do you use the $node->word and when do you use the $edit["word"]? Is it a matter of drupal versions?

If I was more comfortable with this, I'd update the developer documentation.
Joe Lombardo | joe@familytimes.com | My Blog