PHP Form Submission: Recognize Image Input Buttons
As you probably know, you can recognize a form submission from a "submit" input type by placing the following code in the "processing" PHP script:
if(isset($_POST['submit'])) { /* do stuff */ }
Did you know, however, that when using an "image" input type to submit the form, the above wont work? You need to add a "_x" to the field name in PHP:
if(isset($_POST['submit_x'])) { /* do stuff */ }
Odd, huh? This works the same when using a form "GET" method.
![5 Awesome New Mozilla Technologies You’ve Never Heard Of]()
My trip to Mozilla Summit 2013 was incredible. I've spent so much time focusing on my project that I had lost sight of all of the great work Mozillians were putting out. MozSummit provided the perfect reminder of how brilliant my colleagues are and how much...
![Animated 3D Flipping Menu with CSS]()
CSS animations aren't just for basic fades or sliding elements anymore -- CSS animations are capable of much more. I've showed you how you can create an exploding logo (applied with JavaScript, but all animation is CSS), an animated Photo Stack, a sweet...
![Create Classy Inputs Using MooTools’ OverText]()
The MooTools More library is a goldmine. A treasure chest. Pirates booty, if you will (and, of course, I will). More is full of plugins that add a lot of class and functionality to your website with minimal effort.
![JavaScript Copy to Clipboard with Branding]()
I published a post a year ago detailing how you can copy to the clipboard using JavaScript. The post was very popular and why would it be? Copying content from a webpage without needing to use the default browser functions is awesome. One trend I've...
The _x and _y represent the coordinate location you clicked the image at.
Think this is only an issue with IE.
Yeah. The _x- and _y-coordinates are great for improving the security of a form! I’ve used this to determine if the form has been filled by a human. A spam-bot won’t submit any coordinates but a human has to click on the button and so there will always be coordinates (you’ll have to deactive submitting with the ENTER-button).
@Matthias: Good point on the security enhancement — I’ve never though of that!
@ Matthias
Thanks for posting your comment. I think telling the user that the ENTER button has been deactivated for bot protection is easier than having the user type in a captcha.
I’ll definitely be looking into that method and most likely incorporating it into my projects.
@Braxo – Wait – “Enter button” is deactivated? How would this affect someone who cannot use a mouse/relies on accessibility tools to fill out forms and the like?
Some sites cannot get away with it (coughtargetcough).
You can save yourself the trouble and just give the input a name attribute and check for that. Saves from changing code in two places (the input and the PHP submit validation).
<input type="image" src="image.png" name="submitted" value="Submit" />
I should clarify that…
It saves from changing code in 2 places should you want to change to/from an image submit or a standard submit.