Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:05:17+00:00 2026-05-26T03:05:17+00:00

I have a file upload form how can I retain this file when there

  • 0

I have a file upload form

how can I retain this file when there are other validation errors so that the user doesn’t have to upload the file again?

I tried this in my validation function but it doesn’t work:

function mymodule_someform_validate($form, &$form_state) {
  $form_state["values"]["some_field"] = some_value;
}

the $form_state[“values”] variable is not available in my form definition function – mymodule_someform($form, &$form_state)

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:05:17+00:00Added an answer on May 26, 2026 at 3:05 am

    Just use the managed_file type, it’ll do it for you:

    $form['my_file_field'] = array(
      '#type' => 'managed_file',
      '#title' => 'File',
      '#upload_location' => 'public://my-folder/'
    );
    

    And then in your submit handler:

    // Load the file via file.fid.
    $file = file_load($form_state['values']['my_file_field']);
    
    // Change status to permanent.
    $file->status = FILE_STATUS_PERMANENT;
    
    // Save.
    file_save($file);
    

    If the validation fails and the user leaves the form, the file will be automatically deleted a few hours later (as all files in the file_managed table without FILE_STATUS_PERMANENT are). If the validation doesn’t fail, the submit handler will be run and the file will be marked as permanent in the system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where the user can upload a zip file, it works
I have a file upload form that is being posted back to a servlet
I have a form that excepts a file upload in ASP.NET. I need to
I have a method set up that uses jquery form for a file upload
I have an upload form where users can upload images that are currently being
I have that basic, well known multiple file upload form. Something like that... <input
I have this form to upload an xml file to server, I am using
I have a form that allows the user to add as many upload forms
I have a pretty standard upload form - user picks a file, then hits
We have got an extjs 3.1.1 form with file upload field ( http://www.extjs.com/deploy/dev/examples/form/file-upload.html from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.