forms: images for submit buttons?
I have a form with 3 submit buttons. Depending on the submit button clicked the next page redirects you to the proper place. I can use input type='image' instead of type='submit' and it will work, but it doesn't send over which button was clicked.
Is there a way to make this happen?
Thanks.
ROB posted this at 16:13 — 8th July 2002.
They have: 447 posts
Joined: Oct 1999
<?php
<FORM ACTION=\"\" METHOD=\"get\">
<INPUT TYPE=\"image\" NAME=\"button1\" SRC=\"path/to/image1.jpg\" ALT=\"Option 1\">
<INPUT TYPE=\"image\" NAME=\"button2\" SRC=\"path/to/image1.jpg\" ALT=\"Option 2\">
<INPUT TYPE=\"image\" NAME=\"button3\" SRC=\"path/to/image1.jpg\" ALT=\"Option 3\">
</FORM>
if($_REQUEST['button1_x'] || $_REQUEST['button1_y']) {
echo \"<H2>You clicked button 1.</H2>\";
}
elseif($_REQUEST['button2_x'] || $_REQUEST['button2_y']) {
echo \"<H2>You clicked button 2.</H2>\";
}
elseif($_REQUEST['button3_x'] || $_REQUEST['button3_y']) {
echo \"<H2>You clicked button 3.</H2>\";
}
?>
Suzanne posted this at 18:13 — 8th July 2002.
She has: 5,507 posts
Joined: Feb 2000
Each form really should only have one submit button. You might want to rethink how you're setting up the choices. Do you have an url we can see and maybe we can come up with a better solution?
The Webmistress posted this at 19:54 — 8th July 2002.
She has: 5,586 posts
Joined: Feb 2001
It might be better to have the three options as menu choices and have the relevant redirects associated to them instead of the submit buttons.
ROB posted this at 20:37 — 8th July 2002.
They have: 447 posts
Joined: Oct 1999
alternatively, you could do something like this:
<script LANGUAGE="javascript" TYPE="text/javascript">
function SetAndSubmit(val) {
document.theform.selecttype.value = val;
document.theform.submit();
}
</script>
<FORM NAME="theform" ACTION="formhandler.php" METHOD="get">
<INPUT TYPE="hidden" NAME="selecttype" VALUE="">
<P><INPUT TYPE="text" NAME="somefield" VALUE=""></P>
<P>
<IMG SRC="path/to/image" ONCLICK="SetAndSubmit(1)" ALT="button 1">
<IMG SRC="path/to/image" ONCLICK="SetAndSubmit(2)" ALT="button 2">
<IMG SRC="path/to/image" ONCLICK="SetAndSubmit(3)" ALT="button 3">
</P>
</FORM>
now your formhandler will get 'selecttype' with a value of 1,2 or 3 depending on which button was clicked
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.