field_attach_form removes image field default value when submit I need to get some fields of a node edit form, for that purpose I use field_attach_form() to get the fields that I want with the value of the node.

Here's an example of the code of my form function:

function my_form($form, &amp;$form_state, $node_id, $fields) {
  $node = node_load($node_id);
  $node_form = $form;
  field_attach_form('node', $node, $node_form, $form_state);

  foreach ($fields as $field) {
    if ($field-&gt;show) {
      $form[$field-&gt;name] = array('#type' =&gt; 'fieldset', '#title' =&gt; t('Field'), '#tree' =&gt; TRUE,);
      $form[$field-&gt;name]['override'] = array('#type' =&gt; 'checkbox', '#title' =&gt; t('Override'),);
      $form[$field-&gt;name][$field-&gt;name] = $node_form[$field-&gt;name];
      $form[$field-&gt;name][$field-&gt;name]['#states'] = array(
        'enabled' =&gt; array(
          ':input[name="' . $field-&gt;name . '[override]"]' =&gt; array('checked' =&gt; TRUE)
        ),
      );
    }
  }

  return $form;
}


I just wrap every field (that I want to show) in a fieldset with a checkbox.

One of the field is an image type, when field_attach_form loads the field, it shows the image thumbnail and the image file name perfectly, but when I click submit (without edit the field content) the value of the field is empty. In fact, the image field is required so the validation fails.

When I remove the previous image and upload a new one, it works perfectly. Am I missing something?
I found a workaround: I just have the fields twice, one enabled and the other disabled. With the checkbox I show one or another.

function my_form($form, &amp;$form_state, $node_id, $fields) {
  $node = node_load($node_id);
  $node_form = $form;
  field_attach_form('node', $node, $node_form, $form_state);

  foreach ($fields as $field) {
    if ($field-&gt;show) {
      $form[$field-&gt;name] = array('#type' =&gt; 'fieldset', '#title' =&gt; t('Field'), '#tree' =&gt; TRUE,);

      $form[$field-&gt;name]['override'] = array('#type' =&gt; 'checkbox', '#title' =&gt; t('Override'),);

      $form[$field-&gt;name][$field-&gt;name] = $node_form[$field-&gt;name];
      $form[$field-&gt;name][$field-&gt;name]['#states'] = array(
        'visible' =&gt; array(
          ':input[name="' . $field-&gt;name . '[override]"]' =&gt; array('checked' =&gt; TRUE)
        ),
      );

      $form[$field-&gt;name][$field-&gt;name . 'disabled'] = $node_form[$field-&gt;name];
      $form[$field-&gt;name][$field-&gt;name . 'disabled']['#disabled'] = TRUE;
      $form[$field-&gt;name][$field-&gt;name . 'disabled']['#states'] = array(
        'visible' =&gt; array(
          ':input[name="' . $field-&gt;name . '[override]"]' =&gt; array('checked' =&gt; FALSE)
        ),
      );
    }
  }

  return $form;
}


It seems that the action enabled / disabled is buggy.