Jump to content
iwato

The FORM Attribute

Recommended Posts

QUESTION ONE:  When using the form attribute with a non-form element to redirect the contents of the non-form element to the form element, will confusion be created, if the non-form element is included in a form element different from the form element that contains the  type='submit' input element?

QUESTION TWO:  Are fieldset elements an exception in this regard? Or, are they, too, treated as non-form elements.

Share this post


Link to post
Share on other sites

The form attribute only applies to form control elements. It doesn't exist on elements like <div> or <p>. What kind of element are you referring to when you say "non-form element"?

This is regarding the form attribute from the MDN page for the <input> element:

Quote

The form element that the input element is associated with (its form owner). The value of the attribute must be an id of a <form> element in the same document. If this attribute is not specified, this <input> element must be a descendant of a <form> element. This attribute enables you to place <input> elements anywhere within a document, not just as descendants of their form elements. An input can only be associated with one form.

When the element is a descendant of a <form> element the form attribute is not needed. If the element is not inside a <form> then the form attribute will indicate which form the element belongs to so that when the form is submitted the element's value is added to the data that is sent.

I'm not certain how fieldset elements behave, I would guess that the fieldset's children would belong to the same form that the fieldset belongs to, but it can be easily confirmed with an experiment.

Experiments can be done with the form attribute by submitting the form and seeing which values get sent to the server. My guess before doing experiments is that a child of one form that has a form attribute from a different form will be added as a value when either of the two forms are submitted.

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi, Ingolme!  I can see how use of the term form element can lead to confusion.  On the one hand, it refers to the form tag <form>; on the other hand, it refers to any HTML element related directly to the creation of a form -- both non-control and control elements alike.

Since the form attribute of the fieldset element is not recognized by any recent browser (see W3Schools), I will assume that it is a non-control form element  only useful for decoration and the organization of form-control elements.

To play it safe I will remove all of my non-essential <form> tags.

Originally, all of my control-elements pointed to the same <form> tag, but each was grouped with other control elements in different <form> tags that did not contain a type='submit' control element.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...