Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to wrap all my <input> elements in <form> elements?

Tags:

html

forms

I am using JavaScript to extract values from some <input> elements in my page.

Do I need to wrap all my <input> elements in <form> elements?

What will happen if I do not?

Does it give access to some better features?

like image 661
timbram Avatar asked Apr 19 '15 22:04

timbram


1 Answers

No you don't.

The form is used to send data to the server, like some kind of search mask to query a database.

You can put all your input tags in one form tag.

There are some advantages using a form:

  1. Some browsers save the data and you don't have to reenter it
  2. You can easily send it by pushing enter, not just by clicking on a button

Rule of thumb: If you have some input elements that logically belong together, then put them in a form. To process the data you can either use javascript (onsubmit) or you can send it directly to the server.

like image 63
maraca Avatar answered Sep 20 '22 15:09

maraca