Hi!

I want to make a form and save it's data in my own tables (custom tables) in drupal 7 database. how could I do that?

Thanks!

Comments

shabana.navas’s picture

You need to create your own module and create your tables in a .install file using hook_schema. Then, in your .module file, you can create your form which will save the values entered by the user to your tables in the form submit function. Take a look at hook_schema for more help. Also, the Form API page.

Shabana Navas
snavas@acromedia.com
Software Developer
Acro Media
https://www.acromedia.com
1-800-818-4564
Skype: super.shaba

ej’s picture

Thanks:)

You know, In fact it's not a form...
I want to make a documentation in my web site, and I want to develop it by users, these data may be entered in a basic page or my own content type, and then they will save on my own tables (custom tables). Could I do that?

shabana.navas’s picture

Yeah, if you are going to have your own module to install the new tables, then, I would go ahead and just add hook_node_insert() in the module file and save the data to the tables from there. Something like this:

mymodule_mynode_insert($node) {
  // Grab the info from $node and insert into your tables here...
  db_insert('yourtable')->fields(array(
    'nid' => $node->nid,
    'title' => $node->title,
    'type' => $node->type,
    'name' => $node->user_name
  ))->execute();
}

Shabana Navas
snavas@acromedia.com
Software Developer
Acro Media
https://www.acromedia.com
1-800-818-4564
Skype: super.shaba

Abhay Pai’s picture

test

cirrus3d’s picture

Hi, and thanks for this.

To clarify and save someone time, if a field is is set to AUTO_INCREMENT in the database, just leave it out of the array and don't set it at all.