hook form alter with hidden field, throw an error I try to alter taxonomy edit form.

This is my hook:

function MYMODULE_form_taxonomy_form_term_alter(&amp;$form, &amp;$form_state, $form_id) {
    // hide the desciption field and relations group field
    $form['description']['#type'] = 'hidden';
    $form['relations']['#type'] = 'hidden';

    // set the default value
    $form['description']['#value'] = ' ';
    $form['relations']['weight']['#value'] = 0;
    $form['relations']['parent']['#value'] = array('value' =&gt; '13');

}


But When I submit, It throw me an error:

Warning: Illegal string offset 'value' in taxonomy_form_term_submit_build_taxonomy_term() (line 862 in /Users/tangmonk/MyGit/Drupal/daxuebao/modules/taxonomy/taxonomy.admin.inc).
The problem causing the error is that you are setting your hidden description field value is a string, but the taxonomy module is expecting a text area type array with a 'value' and a 'format', which you cannot replicate with a hidden field.

Unfortunately the term description field is a special property of the term, not a proper field, so you can't remove the field (the taxonomy module relies on it being there).

If you don't want people to see it and you always want it to have an empty value a good option is to restrict it from the user like this:

$form['description']['#access'] = FALSE;


but that doesn't allow you to change the value if you want to.

Another option is to use 'value' instead of 'hidden' as the type, like this:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_taxonomy_form_term_alter(&amp;$form, &amp;$form_state, $form_id) {
  // Hide the desciption field and relations group field
  $form['description'] = array(
    '#type' =&gt; 'value',
    '#value' =&gt; array(
      'value' =&gt; '',
      'format' =&gt; 'filtered_html',
    ),
  );
  // Unset the existing relations fieldset.
  unset($form['relations']);
  // Set hidden values for all the sub-fields of the relations fieldset.
  $form['weight'] = array(
    '#type' =&gt; 'value',
    '#value' =&gt; 0,
  );
  $form['parent'] = array(
    '#type' =&gt; 'value',
    '#value' =&gt; 13,
  );
}


Note the changes to the relations fieldset too:

Since you only want to pass hidden values from the children of the fieldset just remove the fieldset altogether and then set the hidden values (be careful if using other add on modules that add fields to the 'relations' fieldset).

Because the fieldset wasn't using #tree the values passed through in $form_state will just be ['weight'] and ['parent'], not ['relations']['weight'] and ['relations']['parent'] so you can leave the ['relations'] part out when adding the values back in.