Forum Moderators: coopster

Message Too Old, No Replies

Form processing problem with input type=image!

         

dreamcatcher

6:21 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey guys,

I`m using one form with two input buttons, which was working fine:


<input type="submit" name="update" value="Update Template">
<input type="submit" name="restore" value="Restore Template">

if (isset($_POST['update'])
{
code..
}
if (isset($_POST['restore'])
{
code
}

Like I say, working fine.

So, then I had the bright idea of creating images.


<input type="image" name="update" src="update.gif">
<input type="image" name="restore" src="restore.gif">

Unfortunately now the form processing does not work. Doesnt the form element name work the same with images? If I change it back, it works ok again.

Thanks.

Birdman

6:44 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

You probably just need to add a value to the image inputs.

<input type="image" name="update" value="Update Template" src="...">
<input type="image" name="restore" value="Restore Template" src="...">

Birdman

jollymcfats

6:47 pm on Aug 27, 2004 (gmt 0)

10+ Year Member



With image submits, you'll get 2 name/value pairs when the button is clicked. For 'restore', the browser will send 'restore.x' and 'restore.y', and the values are the x/y coordinates of where they clicked on the image.

Try


if (isset($_POST['restore'] ¦¦ isset($_POST['restore_x']))
{
code..
}

..and you'll be fine.

Note that PHP will turn the '.x' suffix into a '_x'...

dreamcatcher

8:08 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jollymcfats, spot on! That works like a charm. Phew, I thought I was going to have to juggle my code around. Excellent!

btw, Birdman I did try adding just the value, but that didnt work.

Thanks for the help.

Birdman

9:06 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Whoa, that's a new one to me as well. Thanks, jollymcfats!

ergophobe

9:47 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'll give you three guesses which browser causes the problem and the first two don't count.

If you have an image button
<input type="image" name="restore" value="Restore Template" src="...">

when the user clicks, Mozilla will return the values

restore = Restore Template
restore_x = number of pixels from top of image
restore_y = number of pixels from left edge of image

IE, however, will *not* return the restore=Restore Template key/value. So you can get caught if you develop in one browser and then test in IE, because

isset($_POST['restore'])

will always return false in IE, but will work as expected in Mozilla (and probably Opera but I don't know off the top of my head).

Tom

dreamcatcher

10:29 pm on Aug 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that information Tom. I do test my code in Mozilla, IE and Opera, so I usually catch any differences.

You learn a new thing everyday.

:)

MarciM

12:48 pm on Sep 2, 2004 (gmt 0)



I stumbled upon an even simpler workaround, but I don't know if it will work in your situation.

I had a similar problem with a JSP page. Form worked perfectly with a button with input type "submit", but wouldn't work with button an "image" type. Another image button on the same page DID work, however, which really boggled me. When I compared the two, I discovered that completely by accident, I had also assigned the working button an ID of "action". I then changed the other button to:

<input name="action" id="action" type="image" value="dummy" src="images/button.gif">

Lo and behold, it worked in IE and Netscape 7. I cannot explain it, I only know that it fixed the problem.

jatar_k

4:23 pm on Sep 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld MarciM

coopster

5:00 pm on Sep 2, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Thanks for the possible workaround here, MarciM, but that won't work with PHP. I'm a bit surprised it works with JSP. I would tend to think that IE won't send the $_POST variable any other way except as ergophobe mentioned.