- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Can you nest HTML forms?
In HTML, we cannot nest HTML forms, but we can add multiple forms. Let us see an example of multiple forms, wherein we will add more than one form, upload buttons and multiple Submit buttons.
First, we will set the 1st form. This allows uploading only a single file −
<form action="/details.php"> <label for="myfile">Select a file:</label> <input type="file" id="myfile" name="myfile"><br><br> <input type="submit"> </form>
Just after that, we have used <hr> and then comes the 2nd form. This allows uploading multiple files −
<form action="/details.php"> <label for="myfile">Select a file:</label> <input type="file" id="myfile" name="myfile" multiple><br><br> <input type="submit"> </form>
Example
On a single web page, both the forms will work perfectly with two separate submit buttons. Let us now see the complete example −
<!DOCTYPE html> <html> <body> <h1>Resume</h1> <p>Upload the resume:</p> <form action="/details.php"> <label for="myfile">Select a file:</label> <input type="file" id="myfile" name="myfile"><br><br> <input type="submit"> </form> <hr> <p>Upload multiple project files:</p> <form action="/details.php"> <label for="myfile">Select a file:</label> <input type="file" id="myfile" name="myfile" multiple><br><br> <input type="submit"> </form> </body> </html>
Output
Click Choose File from the 1st form −
Select any file and click Open. We selected Resume.docx and the same is visible −
Above, the text Resume.docx is visible under the 1st form.
Now, click Choose Files from the 2nd form and select multiple files as shown below −
We selected Download.csv and Resume.docx above and the same is visible −
Above, under the 2nd form, 2 files text is visible.