ebrish mateta
ebrish mateta

Reputation: 21

Difference between form id and form name used in html

I want to know the exact difference between form id and form name used in html.

Upvotes: 2

Views: 5148

Answers (2)

Steve
Steve

Reputation: 11

Yes...

You can have a form for email... and have many of them (from a while loop)... They are all email forms (the same) but uniquely identified by id=each user displayed on the page.

<form name="email" id="<?php echo $id; ?>" method=...

Upvotes: 1

scunliffe
scunliffe

Reputation: 63588

Do you mean on the form's elements: e.g. button/input/select & textarea elements?

If so, the name attribute is what is sent when the form is submitted. The id attribute uniquely identifies any element on the page.

The best example I can think of is radio buttons.

Each radio button belongs to a set, and the set has a name. However you may want to link to a particular button by id.

<input type="radio" name="color" id="c1" value="r"/><label for="c1">Red</label>
<input type="radio" name="color" id="c2" value="y"/><label for="c2">Yellow</label>
<input type="radio" name="color" id="c3" value="b"/><label for="c3">Blue</label>

When the form is submitted, only the selected option is sent: (e.g. Yellow)

?color=y

Upvotes: 5

Related Questions