Error in validation of managed_file field with Form API To begin I worked with this solution but a wild error appear: Image Upload in a Custom Module

Here is my code : 

function module_top_content_equipe_admin_form(){
  $default = get_variable_value(variable_get('module_top_content_equipe_display', ''));
  $default_image = variable_get('module_top_content_equipe_image', '');
  $form['module_top_content_equipe_display'] = array(
    '#type' =&gt; 'text_format',
    '#name' =&gt; 'module_top_content_equipe_display',
    '#title' =&gt; t('Content of the block'),
    '#description' =&gt; t("Text to display"),
    '#format' =&gt; 'filtered_html',
    '#default_value' =&gt; $default,
  );
  $form['module_top_content_equipe_image'] = array(
    '#type' =&gt; 'managed_file',
    '#name' =&gt; 'module_top_content_equipe_image',
    '#title' =&gt; t('Top Content page l equipe Image'),
    '#description' =&gt; t("Image should be less than 400 pixels wide and in JPG format."),
    '#default_value' =&gt; $default_image,
    '#upload_location' =&gt; 'public://',
  );
  return system_settings_form($form);
}

function module_top_content_equipe_admin_form_submit($form, &amp;$form_state){
  if (isset($form_state['values']['module_top_content_equipe_image'])) {
    $file = file_load($form_state['values']['module_top_content_equipe_image']);

    $file-&gt;status = FILE_STATUS_PERMANENT;

    file_save($file);
  }  
}


and my error when I submit the form


  Fatal error: Cannot unset string offsets in /includes/form.inc on line
  2157


Thank you with advance
There's a bug in the way system_settings_form() handles managed_file types. It's to do with the upload/remove buttons and parent elements (if you read the whole issue you hould get a good take on what's going on).

I don't know if it's the same error as I was having, but adding code like the following to the top of the form's submit handler fixed it for me:

foreach($form_state['buttons'] as $delta =&gt; &amp;$button) {
  if (preg_match('/module_top_content_equipe_image_(upload|remove)_button/i', $button['#name'])) {
      $button['#parents'] = array();
    }
  }


Not ideal by any means, but it does work.

On another note, the #process property attached to the managed_file item is unnecessary. That code should be run in the form's submit handler, and since your submit handler is named in the right convention it will be run when the form is submitted, which is when you need it to.

Try removing the #process line altogether and see what happens.