Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should we still use form element in html? [closed]

With modern javascript (and js framework too!) and different ways to do a sync/async actions (POST, GET etc,..) I am still wondering why would one still want to use form element?

Is it due to code semantics and actually "specifying" an area from which something is submitted?

Is it because form acts as a helper that "collects" (poorly I would say) data?

All of the above can be easily done in javascript, so I cannot think of any other reason for using form for submitting data?

like image 947
mko Avatar asked Mar 07 '19 09:03

mko


People also ask

Why should I use the form element?

Semantics and accessibility # If something is a form, use a form element. This helps assistive devices like screen readers better understand the content of the page and give the person using them more meaningful information.

Is it necessary to use form in HTML?

If all your input field is doing is providing a UI (user interface) hook for interactions, then you can put the input fields into the HTML without including a FORM tag.

What is the purpose of form element in HTML?

An HTML form is used to collect user input. The user input is most often sent to a server for processing.

Are forms still used in HTML?

Form tags are still necessary if you want to be able to submit the form without AJAX (which may be useful in the early stages of development).


1 Answers

Writing unobtrusive JavaScript that works using progressive enhacement continues to be best practise because there are plenty of circumstances where JavaScript fails.

Aside from that, just because you can do something with JavaScript doesn't mean you should do something with JavaScript. Often a regular form submission will give all the desired effects with less work.

And on top of that, a form is a useful element to collect data with even if you do use JavaScript. For example, you can use a form element to populate a FormData element.

Forms provide semantic data to group form controls, this is heavily used by screen readers.

As mentioned in comments, some password managers use them to identify grouped login form controls.

like image 58
Quentin Avatar answered Oct 14 '22 17:10

Quentin