What are the requirements of maintaining a 'name' attribute in an 'HTML' tag?

12

What do you need to keep a name attribute in a HTML tag? its characteristics are the same as the id attribute that still has other utilities such as the key of the $_POST and $_GET

asked by anonymous 09.11.2015 / 16:02

3 answers

10

Objective

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

Other Utilities

Forms Submission for IFRAMES

Ricardo, as well as serve as keys to POST and GET , another feature I know is to make a form submission to 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 the form is submitted, the result will be displayed in iframe , rather than refreshing the page. Although action is pointing to another page, it will render within iframe .

This is a feature I know. Maybe there are others, we'll see the other answers:)

Form Access Via Javascript

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

You can do this:

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

So we can access this form easily through Javascript:

document.matricula.submit();
    
09.11.2015 / 16:06
7

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

The name attribute can also occur repeatedly with the same value on elements that are repeated on the page (for example, checkboxes). Already repeating id is recipe for problems.

    
09.11.2015 / 16:07
4

These are the names of the parents that are sent in a GET or POST request. No 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'];
    
09.11.2015 / 16:07