“Image” input type: why a “name” attribute?
What is the use of the name
attribute in the image
input开发者_JAVA百科 type?
watch this:
<?
var_dump($_REQUEST);
?>
<form method="post" action="test.php">
<input type="image" name="test" src="design/back2.jpg">
</form>
after sending the form you get this:
array(2) { ["test_x"]=> string(2) "94" ["test_y"]=> string(2) "80" }
namy_x and name_y tells you where the user clicked on that image.
Definition and Usage
The name attribute specifies a name for an input element.
The name attribute is used to identify form data after it has been submitted to the server, or to reference form data using JavaScript on the client side.
Note: Only form elements with a name attribute will have their values passed when submitting a form.
The image input was designed as a server side image map. When you click on it, the coordinates you click on are sent to the server. The name is required so that the server side process can find those coordinates amongst the rest of the form data.
Although browser support is weaker then for other elements, the name and value are also submitted. This allows, in the case of multiple image images / submit buttons, for the server to distinguish which one was activated (since only the activated submission control is successful (i.e. included in the submitted data)).
精彩评论