I think the respondents so far completely missed your question… See… you can have multiple submits… for example:
<input type="submit" name="profileSubmit" value="Add me to profile and newsletters" />
<input type="submit" name="profileSubmit" value="Add just my profile" />
When you click on the appropriate submit, the value of the one you clicked on will be passed.
<?php
echo 'You clicked on "',$_request['profileSubmit'],'"<br />';
?>
Will echo the value of the one you clicked on!
You can also use different names with the same value… though not as useful.
<input type="submit" name="searchSite" value="Search" />
<input type="submit" name="searchWeb" value="Search" />
Only the submit you click on will have it’s value sent.
<?php
if (!empty($_request['searchSite'])) {
// they clicked on searchSite
} else if (!empty($_request['searchWeb'])) {
// they clicked on searchWeb
}
?>
using multiple names is often more convenient since you can then make the values anything you want, and only have to check for ‘empty’.
<input type="submit" name="searchSite" value="Search Site" />
<input type="submit" name="searchWeb" value="Search Web" />
That would also work with the same !empty check as above!
A LOT of allegedly experienced web developers are blissfully unaware of this powerful technique. Not too surprising though given the number of people who can’t even be bothered to use LABEL, FOR, FIELDSET, LEGEND, and do idiotic nonsense like wrapping form elements in tables or lists.
Funny since the same applies to radio buttons…
<fieldset>
<legend>What is your favorite web programming language?</legend>
<label for="favoritePHP">PHP</label>
<input type="radio" id="favoritePHP" name="favoriteLanguage" value="php" />
<br />
<label for="favoriteASP">ASP</label>
<input type="radio" id="favoriteASP" name="favoriteLanguage" value="asp" />
<br />
<label for="favoriteJAVA">JAVA</label>
<input type="radio" id="favoriteJAVA" name="favoriteLanguage" value="java" />
<br />
<label for="favoriteJS">JAVASCRIPT</label>
<input type="radio" id="favoriteJS" name="favoriteLanguage" value="js" />
<br />
<label for="favoritePerl">PERL</label>
<input type="radio" id="favoritePerl" name="favoriteLanguage" value="perl" />
<br />
<label for="favoritePYTHON">PYTHON</label>
<input type="radio" id="favoritePYTHON" name="favoriteLanguage" value="python" />
<br />
<label for="favoriteOther">OTHER</label>
<input type="radio" id="favoriteOther" name="favoriteLanguage" value="other" />
</fieldset>
type=“submit” and type=“image” work pretty much the exact same way!
ID is for the FOR attribute to point at and for direct styling/script access. Name is what gets sent to the server as the result index, value being the result. In the case of radio buttons, submits, and images, if you have multiple elements with the same name the one you clicked on/focused last is the one that has it’s value sent.
About the only element you’ll see people putting NAME on for no good reason is FORM; I suspect this is a holdover from Netscape 4 era scripting – today that’s just stupid/pointless.
Also, if there’s only one submit method, then you are right, there’s no legitimate reason to slap NAME on it.