Drupal 6: finding out which button is clicked when using a image_button element

When using multiple image_button elements in a form, there's no easy way to found out which one was clicked. This page contains a solution which allows you to identify the clicked image_button.

Recently I was building a module which showed a rather complex form. The form contained a mix of submit button and image_button elements.

In the submit handler I wrote some code to discover which button was clicked.

I made it work in the following case:

  • I gave each button and image_button a unique attribute '#layout' of which the value uniquely identified the button.
  • The image_button must not have a '#value' or '#default_value' attribute.
  • In the submit handler, check the value of the $form_state['clicked_button']['#layout'] to find out which button was clicked!


You might also be interested in...