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

NOTE

When you submit the form using the keyboard (for example, with the Enter key), both coordinates are 0.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net