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
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
Generally, the name attribute is used to represent a collection of values sent through a form to the server.
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();
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.
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'];