Form Fields Not Submitting? Nested Forms and the HTML form Attribute
Raheel Shan
July 22nd, 2025 · 8 min read
If some of your form fields are missing from the submitted data, or the submit button does nothing, the usual cause is a form nested inside another form. The browser does not allow it, so it closes your form early and every field after that point ends up outside it. The fix is to stop depending on nesting and tie each field to its form with the HTML form attribute. This post shows how to confirm the cause, the fix, and the other reasons a form field is not submitted.
Quick answer
- Open DevTools and look at the Elements panel. If your fields sit outside the
<form>element, the form was closed early. - Look for a second
<form>inside the first (a plugin, a component or a partial). Remove it, or move it out. - Give your form an
idand addform="thatId"to every input, select, textarea and button that should belong to it.
Check the simple causes first
Before blaming nesting, rule out these. They cause most "input field not saving text" problems:
- The input has no
nameattribute. Only named fields are submitted. - The input is
disabled. Disabled fields are never sent (usereadonlyif you only want to lock it). - Unchecked checkboxes and radios send nothing at all, by design.
- The button is outside the form, or its
typeisbuttoninstead ofsubmit. - Two elements share the same
id, and aform="..."or label points at the wrong one. - JavaScript calls
preventDefault()on submit and never sends the data.
If none of these is the problem, look at the DOM structure.
The real problem: a form nested inside a form
Nested forms are invalid HTML. They show up when a template includes a partial that has its own form, when a table row needs its own delete button, or when a plugin needs a form for uploads or ratings.
<form id="mainForm" action="/submit" method="POST">
<input type="text" name="username" />
<form class="upload-form" action="/upload" method="post">
<input type="file" name="file" />
</form>
<input type="email" name="email" />
<button type="submit">Submit</button>
</form>
When the browser parses this HTML, it ignores the inner opening <form> tag but still obeys the inner closing </form>. That closing tag ends the outer form. This is what the browser actually builds:
<form id="mainForm" action="/submit" method="POST">
<input type="text" name="username" />
<input type="file" name="file" />
</form>
<input type="email" name="email" />
<button type="submit">Submit</button>
The email field and the submit button now sit outside the form. They look fine on screen, but they are not part of it, so they are not submitted and the button does nothing.
If a script inserts the inner form into an existing page with DOM methods such as appendChild, the nested form can exist in the DOM. The form owner of each field is then its nearest ancestor form, which is a different problem with the same symptom: fields end up in the wrong form.
The fix: the HTML form attribute
The form attribute links an input, select, textarea, button or fieldset to a form by its id, wherever it sits in the page. Nesting no longer matters.
<form id="mainForm" action="/submit" method="POST">
<input type="text" name="username" />
</form>
<form class="upload-form" action="/upload" method="post">
<input type="file" name="file" />
</form>
<input type="email" name="email" form="mainForm" />
<button type="submit" form="mainForm">Submit</button>
The email field and the button are outside mainForm in the markup, but they belong to it. Pressing Enter in a linked field submits that form, and new FormData(document.getElementById('mainForm')) includes the linked fields too.
The pattern I use on messy pages
On large admin pages with tabs, modals and plugins, I stop fighting the layout:
- Open the form at the top and close it straight after the hidden fields (
_token,_method, record ids). - Place the visible fields anywhere in the template: tabs, cards, modals.
- Add
form="mainForm"to every field and to the submit button.
<form id="mainForm" action="/submit" method="POST">
<input type="hidden" name="_token" value="..." />
</form>
<div class="dropzone" id="upload"></div>
<div class="star-rating" data-score="4"></div>
<input type="text" name="username" form="mainForm" />
<input type="email" name="email" form="mainForm" />
<button type="submit" form="mainForm">Submit</button>
In Laravel Blade, the @csrf and @method('PUT') directives go inside that empty form. Fields added later by Alpine, Vue or a JS template submit correctly as long as they carry the form attribute.
Several forms on one page
The same attribute keeps multiple forms apart, even when their fields are mixed together in the layout:
<form id="profileForm" method="POST" action="/save-profile"></form>
<form id="passwordForm" method="POST" action="/change-password"></form>
<input type="text" name="name" form="profileForm" />
<input type="email" name="email" form="profileForm" />
<button type="submit" form="profileForm">Save profile</button>
<input type="password" name="current" form="passwordForm" />
<input type="password" name="new" form="passwordForm" />
<button type="submit" form="passwordForm">Change password</button>
This also solves table rows that each need their own button. Put one empty form per action outside the table, and point each row's button at it. If you are building delete buttons in a table, see Four Ways to Trigger Delete Row from a Table.
Limits and when not to use it
- It is not needed in simple forms. If nothing injects markup, a normal nested-free
<form>is easier to read. - Every linked field needs the attribute. One forgotten input falls back to its parent form, or to none.
- The
idmust be unique on the page. A duplicateidlinks fields to the first form that has it. - The attribute links fields, it does not remove invalid nesting. Fix the nested form when you can; use
formwhen you cannot.
For a clean single form that handles both create and edit in Laravel, see Laravel findOrNew(): Create or Edit with One Form.
FAQ
Why is my form input not saving text? Check that the field has a name, is not disabled, and sits inside the form or has a form attribute pointing to it. A field outside the form element is never submitted.
Why is my submit button not working? It is probably outside the form after the browser closed the form early. Add form="yourFormId" to the button, or fix the nested form above it.
Can you put a form inside a form in HTML? No. The parser ignores the inner opening tag and the inner closing tag closes the outer form. Use separate forms and the form attribute.
Does the form attribute work in all browsers? Yes in all current browsers, including Chrome, Firefox, Safari and Edge. Internet Explorer 11 does not support it.
How do I see which form a field belongs to? In the browser console, run document.querySelector('[name=email]').form. It returns the owning form element, or null if there is none.
Get a second pair of eyes on your code
We open your repository together. I review structure, queries, security and naming.
You leave with fixes you can apply the same day.
Found this useful?
Support the work that goes into these posts.