How to save custom fields when using hook_form_FORM_ID_alter? I am implementing hook_form_FORM_ID_alter(). I have managed to setup for, and be able to collect custom values from the fields. When I submit the form, the node is created without my custom fields (i.e field_1 an field_2).

function mymodule_form_AYG_node_form_alter(&amp;$form, &amp;$form_state, $form_id){
  $options_first = _mymodule_get_first_dropdown_options();

  $selected = isset($form_state['values']['field_1']) ? $form_state['values']['field_1'] : key($options_first);

  $form['field_1'] = array(
    '#weight'=&gt; -15,
    '#type' =&gt; 'select',
    '#title' =&gt; 'field 1',
    '#options' =&gt; $options_first,
    '#default_value' =&gt; $selected,    
    '#ajax' =&gt; array(
      'callback' =&gt; 'mymodule_dependent_dropdown_callback',
      // 'wrapper' =&gt; 'dropdown-second-replace',
    ),
  );

   $form['field_2'] = array(
    '#weight'=&gt; -14,
    '#type' =&gt; 'select',
    '#title' =&gt; 'field:',

    '#prefix' =&gt; '&lt;div id="dropdown-second-replace"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',

    '#options' =&gt; _mymodule_get_second_dropdown_options($selected),
    '#default_value' =&gt; isset($form_state['values']['field_2']) ? $form_state['values']['field_2'] : '',
  );


  $form['#validate'][] = 'mymodule_form_validate';
  $form['#submit'][] = 'mymodule_form_submit';

  return $form;
}

function mymodule_form_submit(&amp;$form, $form_state) {    
  // I can see values for the custom fields here. 
  // How do I store them in the node?
  dpm($form_state);
}


I have installed the Entity API module, and tried the proposed solution. It gives me an error.

function mymodule_form_submit(&amp;$form, $form_state) {
  $node = $form_state['node']; 
  $node = node_load(arg(1));

  krumo($node);  // Getting FALSE here

  $obj = entity_metadata_wrapper('node', $node);
  $obj-&gt;field_1 = $form_state['values']['field_1'];
  $obj-&gt;field_2 = $form_state['values']['field_2'];
  $obj-&gt;save(); 
}


This is the error:


  EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 735 of E:\wamp\www\Classified\sites\all\modules\entity\includes\entity.wrapper.inc).
  The website encountered an unexpected error. Please try again later.
The only thing your form alter has done it added fields to a form. But you need somewhere to store the values of those fields.

When you add a field to an entity (node) using the Field UI module Drupal creates 2 database tables. One to store the field values and one to store older revisions of that fields value. Without these tables you don't have anywhere to store the values.

Here are steps to add that field your node bundle:


Make sure the Field UI module is enabled.   
From the admin toolbar visit Structure > Content types > AYG (the name of your node type) > Manage fields.
On this page add your new fields and configure as required.


Now your new fields will show on your node creation / edit forms and you will have tables to store the values of those fields.