ashish dabral
ashish dabral

Reputation: 69

Name field not set for form input fields

I have a form and it contains multiple input fields. What if i don't provide an id or name to each and every field. will that field be submitted with some default name or won't be submitted at all.

This is just a query. No code involved. Thanks

Upvotes: 0

Views: 645

Answers (2)

Basith
Basith

Reputation: 1075

The form will still get submitted but you won't be able to get the 'post' values when the form has been submitted.

Upvotes: 0

Quentin
Quentin

Reputation: 943207

Form controls without names cannot be successful controls and will not be submitted.

The value of a control without a name will not be included in the submitted form data.

See HTML 4:

A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.

or HTML 5:

If any of the following conditions are met, then skip these substeps for this element … The field element is not an input element whose type attribute is in the Image Button state, and either the field element does not have a name attribute specified, or its name attribute's value is the empty string.


The id is irrelevant to the success of a control. Only the name matters there.

The id is still important to include as it is the best way to associate a <label> element with a control (and has other uses via JS and CSS).

Upvotes: 1

Related Questions