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

  • SEARCH
  • Home
  • 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 3792116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:34:23+00:00 2026-05-19T12:34:23+00:00

I’m noticing what I think is a bug with Zend_Form_Element_File. Can others please test

  • 0

I’m noticing what I think is a bug with Zend_Form_Element_File. Can others please test it and tell me if they get the same result. On a failed form, all fields re-populate except the value of Element_File.

My form has 2 text fields and 1 file field and all are required.

$name = new Zend_Form_Element_Text('name');
$name->setLabel('Name');
$name->setRequired(true);
$this->addElement($name);

$name2 = new Zend_Form_Element_Text('name2');
$name2->setLabel('Name2');
$name2->setRequired(true);
$this->addElement($name2);

$file = new Zend_Form_Element_File('file');
$file->setLabel('Test file')
     ->setDestination(APPLICATION_PATH);
$file->setRequired(true);
$this->addElement($file);

$submit = new Zend_Form_Element_Submit('submit');       
$submit->setLabel('Submit')
$this->addElement($submit);  

Normally when a form fails, it automatically populates whatever fields were filled out, but it doesn’t work for the file field, and I have to manually select the file again, in addition to correcting the other fields that need correcting.

First of all, could others confirm this?

I think the problem is related to the markup of the file field. I’m seeing that the first <input> is the file size and then the file itself comes in the second <input>.

<dd>
<input type="hidden" id="MAX_FILE_SIZE" value="67108864" name="MAX_FILE_SIZE">
<input type="file" id="file" name="file">
</dd>

and when a valid form is submitted, the post data shows only the first <input> of the file field which is the size [MAX_FILE_SIZE] => 67108864 and not the file itself.

Array ( 
   [name] => test 
   [MAX_FILE_SIZE] => 67108864
) 

When the form is valid, the upload works fine so I know nothing’s wrong with the file field itself, but in the case of a failed form (correct file field but one of the other fields is invalid), the file field is the only field that doesn’t get re-populated when the form renders. So is this a bug? It’s annoying to have to re-add the file when there was nothing wrong with it. Is there a workaround that someone can think of. I tried doing a manual populate in case of invalid form, hoping that it would force the file field to populate, something like this, but it also did not work.

   if(//valid form){
      //process the form
   } else {
       $form->populate($this->_request->getPost());     
   }
  • 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-19T12:34:24+00:00Added an answer on May 19, 2026 at 12:34 pm

    This isn’t a bug with Zend_Form. It’s a limitation HTMLs file upload input element. Browsers will ignore and value set on a file input for security reasons. If this limitation wasn’t in place, malicious websites could pre-populate the file input with things like

    /etc/password
    c:\Windows\Location\Of\Sensative\File.txt
    

    and then auto post the contents of your hard drive to any server.

    One common work around is to use something like the ajax form plugin for jQuery to post the upload via an ajax request. When it fails, the file upload stays selected, as there’s no page refresh.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.