How to fetch the existing value of a form field in the form? I have a minimal form with a single field to add an image to an entity and a save button. I have used managed_file to add the image.

After adding the image from form the image gets saved in db.

Next time the user opens the form, it shows blank field and after adding a value current one gets replaced. What I want to do is user should see the existing value of the field when reopening the form.

How do I do this?

[Edit]: 

Code for my form is:

// Form Definition
function custom_profile_form($form, &amp;$form_state){
  $form = array();
  $form['picture'] = array(
    '#title' =&gt; t('File'),
    '#type' =&gt; 'managed_file',
    '#description' =&gt; t('The uploaded file will be processed.'),
  );

  $form['buttons']['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Import'),
  );

  return $form;
}

// Form Validation
function custom_profile_form_validate(&amp;$form, &amp;$form_state) {
  $file = file_save_upload('picture');
  $file-&gt;status = FILE_STATUS_PERMANENT;
  $uploaded = file_save($file);
  $upl = file_move($uploaded, "public://");
  $form_state['storage']['fid'] = $upl-&gt;fid;
}

// Form Submission
function custom_profile_form_submit(&amp;$form, &amp;$form_state) {
    global $user;
    $user1 = user_load($user-&gt;uid);
    $file = file_load($form_state['storage']['fid']);
    $edit = array(
      'picture' =&gt; $file,
    );
    user_save($user1, $edit);
}
You can use #default_value attribute of the managed_file to show the existing value of the field.

You can get the value of fid from database and set value into #default_value.

Example:

$form['picture'] = array(
  '#title' =&gt; t('Image'),
  '#type' =&gt; 'managed_file',
  '#description' =&gt; '',
  '#default_value' =&gt; 1, //fid from database
  '#upload_location' =&gt; 'public://image_example_images/',
);