What is the need to maintain a`name` attribute in a`HTML`tag?

Asked

Viewed 2,891 times

13

What is the need to maintain an attribute name on a tag HTML? its characteristics are equal to those of the attribute id that still has other utilities like being the key of the arrays $_POST and $_GET of PHP.

  • But you’re saying that the id HTML is key to $_POST and $_GET in PHP? No, just the name will stop in these PHP arrays.

  • 1

    Thank you for considering the answer good ;)

3 answers

12


Goal

Generally, the name attribute serves to represent a collection of values, sent through a form, to the server.

Other Utilities

Submission of forms to IFRAMES

Ricardo, besides serving as keys to POST and GET, another feature I know is to make a form submission for a iframe, instead of refreshing the page.

Example:

<form target="meu_iframe" action="form.php">
  <input type="text" name="nome" />
  <input type="submit" />
</form>

<iframe name="meu_iframe">

Consequently, when form Submit is made, the result will be displayed in the iframe, instead of refreshing the page. Although action is pointing to another page, the rendering of it will take place within the iframe.

This is a feature I know about. Maybe there could be others, let’s see the other answers :)

Access to the Form via Javascript

I also remember that it is possible to give a name for a form, even if it is not processed by the server (as stated in one of the answers)

It is possible to do this:

<form name="matricula">
 ...
</form>

Thus, we can access this form easily through Javascript:

document.matricula.submit();

7

The attribute name is suitable for forms, to identify components on the server. The attribute id is suitable for client-side computations.

The attribute name may also occur repeatedly with the same value in elements that repeat on the page (for example, check boxes). Already repeat a id is recipe for trouble.

4

These are the names of the parameters that are sent in a GET or POST request. In HTML:

<form class="" action="index.php" method="post">
    <input type="text" name="name_input_1" value="">
    <input type="text" name="name_input_2" value="">
</form>

In PHP:

$name_input_1 = $_POST['name_input_1'];
$name_input_2 = $_POST['name_input_2'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.