When creating a file select form in HTML, do you need a submit button?

Do you need to add a submit button to:
<form>
     <label for="file-select">Upload</label>
     <input type="file" name="upload" id="file-select">

</form>

 

Category: Development 4 months ago
Ryan M Dunnion
Asked 4 months ago
Ryan M Dunnion

The file select input only selects the file, it does not upload it.

In order to upload it you will need to pass the selected file to an upload function, usually after submitting the form (process it on the <form action="upload.php" method="post"> upload.php script). Thus, needing a submit button.

This can all be avoided however with the power of javascript. Using a javascript event such as onchange, one can upload the selected file without a submit button. The onchange event can call the functions needed to upload the file, and even populate a div with the uploaded picture once complete.

An example of a file uploading form without a submit button 

Important to understand is that html can not upload files.

Html is a client side code, meaning that it is for browsers.

To upload a file to a server, you will need a server side language to process the form input, such as php. Here's one tutorial about the html/php file upload form/function. To find out more, I suggest searches for 'html form file upload php' or some such.

I hope this was helpful. Let me know if you have any more questions, I'll be happy to clarify or answer anything I can.

Omni
Answered 4 months ago
Omni

Please register/login to answer this question.  Click here to login
Cron Job Starts