Help needed with hook_node_submit in custom module to save data I require some help in my custom module, specifically getting the value of a form element added via ajax in hook_node_submit.

First I'll explain the basic module setup needs:


You have created a content type called 'content'. 
You have created a sample taxonomy vocabulary and added some sample terms to it. 
In the content type you add a term reference field with the name 'field_terms' for the newly created vocabulary and allow unlimited values (checkboxes).


Now you enable the module and create new content of type 'content'.

Once you select 2 taxonomy terms, a select list appears with the 2 or more selected terms in it, allowing the user to select one of the above selected terms once more (to define a main term from the selected terms - if that makes any sense)

So, in terms of the module I have written this:

1) I use the function hook_form_alter() and apply it to only $form_id == 'content_node_form' (content type = 'content').

2) In hook_form_alter() I apply '#ajax' to each checkbox for the field_term checkboxes and create a blank container where the select list will be placed after the callback.

3) I have written the function _custom_callback() which gets the selected checkbox term_ids and term_names from the field_terms to create the select list options. It then outputs the select list if 2 or more options have been selected

4) Implement hook_node_submit() to grab the data from the $form_state and move it into the node object (this is where the first errors occur)

5) Implement hook_node_load() to load the values when editing the page

6) Impmeneted hook_node_insert(), hook_node_update() and hook_node_delete() to do the db stuff.

But when I submit the form I receive the following errors - due to hook_node_submit:



I am unsure how to call my object in the node. My form is called 

$form['container']['main_taxonomy_term']


So I presumed this would be correct:

/**
 * Implements hook_node_submit().
 */
function select_main_taxonomy_term_node_submit($node, $form, &amp;$form_state) {

  $value = $form_state['values'];
  // Move the new data into the node object.
  $node-&gt;main_taxonomy_term['tid'] = $value['main_taxonomy_term'];
}


I have looked and tried but I just can not find any clues how to get the data from $form_state and into the node object.

Please find attached the module. maybe someone can help me out as this is driving me insane.

Here is the module:

http://www.megaupload.com/?d=181H4B5F

Many thanks in advance.
So now I can answer my own question:

In my module I had $form['container'] defined in the hook_form_alter(), but the actual field $form['container']['main_taxonomy_term'] wasn't defined yet as I was adding it in my callback, so naturally Drupal didn't know about the field when rendering the form. 

I restructured the module, moved the $form['container']['main_taxonomy_term'] = array(...) into the hook_form_alter(), created a new function to get the select options, calling upon it in various circumstances, added some extra checks for the edit node form as the options had to be built from the database values upon first display, but after that use $form_state else it wouldn't refresh the list upon editing the checkbox selection...

Oh well, so i finally managed to get it working without error message.

Maybe this is helpful for anyone, or maybe it isn't at all.