Thursday, June 25, 2009

The IE Input Image Catch

While working hard at my work (which is why this post is short), I was creating a site that used image inputs. All was well and good when running it in FireFox, but in Internet Explorer, it was a different story.

Problem:
Checking for the input name in the POST variable when using an image type, the PHP looking for the name could not find that input object.

Solution:
Internet Explorer as well as some other browsers, pass the x and y of the image you used for submitting your form instead of the input name. To detect these with PHP, you can check for

isset($_POST['image_x']) || isset($_POST['image'])

if either is true, you can continue to process. You may also note that the browser has converted what would have been image.x into image_x. The period character is swapped out.

Now you should be able to have your input be detected in all major browsers.

No comments: