views:

277

answers:

2

On the site I am developing, I have a file input that users can upload files from. It uses "Ajax" (not really) to send the file to a php file that is bound to an iframe. My question is that Firefox automatically fills in the file input element. Is there a way I can give users the option of clicking the submit button without sending the file? Or do I set the file value to null somehow and check for that in the php file? My code looks like this:

    Name: <input type='text' id='name'><br>
 Description: <textarea id='description' rows=10 columns=100></textarea><br>
 <form id="upload_form" method="post" enctype="multipart/form-data" action="uploadfile.php">
 <input type='hidden' value='' id='descriptionid' name='descriptionid'>
 <input type='file' name="file" id="file" size="27" value="">
 <input type='submit' value='Submit' onclick=';' id='submitPopup'>
 </form>

When the button is clicked it runs a JavaScript method and gets the values of name and description and also submits the input form. How do I let users have the option of uploading a file, and not have it auto filled in by their browser?

A: 

For safety you can not enter data by hand or by JavaScript in an input type file.

andres descalzo
+3  A: 

As a security measure, reading or setting the value of a file input field is not allowed. However, if you call form.reset() that will clear it out for you.

You could even loop through all the other inputs, remember their value, reset the form and then refill the other inputs, so only the files are cleared.

nickf
@nickf: do you have a reference where it is stated that setting the value of a file input field is not allowed?
Peter Mortensen
The statement about security is also in http://www.irt.org/script/1154.htm
Peter Mortensen
@Peter: happy to help. :)
nickf