Processing Graphical Submit Buttons
if (isset($_POST['Submit_x']) && isset($_POST['Submit_y']))
|
Graphical Submit buttons (<input type="image" />) are not only a nice way to spicen up the layout of the form, but they also offer a nice feature: The browser submits the x and the y coordinates of the mouse pointer when clicking on the button. In PHP, this happens by appending _x and _y to the name attribute of the button and writing this into $_GET or $_POST. The preceding code evaluates this information.
Processing Graphical Submit Buttons (image.php; excerpt)
<?php
if (isset($_POST['Submit_x']) && isset($_POST
['Submit_y'])) {
printf('<h1>You clicked at the following
coordinates: x-%s, y-%s</h1>',
htmlspecialchars($_POST['Submit_x']),
htmlspecialchars($_POST['Submit_y'])
);
} else {
?>
<form method="post" action="<?php echo
htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<input type="image" name="Submit" src="sams.gif"
/>
</form>
<?php
}
?>
When you submit the form using the keyboard (for example, with the Enter key), both coordinates are 0. |
|