Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the point of input without name in HTML5?

Tags:

html

php

In HTML5, an input without name is also valid

e.g.

      <input type="text" id="user"  />

But what is the point if I cannot access the form element in my backend PHP code?

like image 334
Howard Avatar asked Aug 02 '11 17:08

Howard


2 Answers

Not all input is used server-side. In many cases it's used for form submission via AJAX. Additionally, a JavaScript app can make use of user input without ever needing to use a form.

like image 58
zzzzBov Avatar answered Oct 23 '22 14:10

zzzzBov


Click the "link" button on any question or answer here on Stack Overflow, you will see an example of an <input> without a name or associated form.

Granted, this particular input is created with javascript - but it's pretty common to see an input field or textarea for copy/paste purposes, for one example.

..and it's also useful for basically anything to do with javascript.

One non-AJAX example I am currently using:

I have a spreadsheet for several dollar amounts to be filled in. I use an <input> field with no name to display the total amount of each column with javascript. On the server side, I don't need a "total amount" field coming through, and I sure as hell wouldn't trust it. The real total amount is calculated on the server side based on the other inputs, but we still show it in real time on the front end for the user.

like image 28
Wesley Murch Avatar answered Oct 23 '22 14:10

Wesley Murch