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="/books/3/489/1/html/2/sams.gif" /> </form> <?php } ?>
|