Using FormAPI to create a simple set of three image_buttons, in the form_submit handler there is no 'op' value set in $form_state and therefore no way to tell which image_button was clicked. Is this a limitation of image_buttons?

Here's what I used to create the form, and it's bare-bones submit handler that shows no information telling me which button was clicked:

function cex_dash_top_icons_block_form( $form_state ) {
  $form = array();
  global $base_url;  
  $projects_icon_path  = '/'.drupal_get_path('module','cex_dash').'/Projects-icon-med.jpg';
  $reporting_icon_path = '/'.drupal_get_path('module','cex_dash').'/Reporting-icon-med.jpg';
  $help_icon_path      = '/'.drupal_get_path('module','cex_dash').'/Help-icon-med.jpg';

  $form['projects'] = array(
    '#type'  => 'image_button',
    '#value' => 'Projects Dash',
    '#src'   => $projects_icon_path,

  $form['reports']  = array(
    '#type'  => 'image_button',
    '#value' => 'Analytics Dash',
    '#src'   => $reporting_icon_path

  $form['help']     = array(
    '#type'  => 'image_button',
    '#value' => 'Documentation Dash',
    '#src'   => $help_icon_path

  return $form;

function cex_dash_top_icons_block_form_submit($form_id, &$form_state) {
  _devReport( 'cex_dash_top_icons_block_form_submit: form_state is "'.print_r($form_state,1).'"' );

And no matter which button is clicked, $form_state['values'] looks like this:

[values] => Array(
  [projects] => Projects Dash
  [reports] => Analytics Dash
  [help] => Documentation Dash
  [form_build_id] => form-b6c762d22d0fd2360d1804ef19043c7d
  [form_token] => 4f0ce5275cc923e8fb27c305b57bf414
  [form_id] => cex_dash_top_icons_block_form

Now, in the larger $form_state array there is a 'clicked_button' array, but that always only has the information for the last image_button.

Do I need to create one mini-form for each image_button?

  • This is not a forum, but a Q&A site; updating a question to show the adopted solution is not the best practice. If you want to show the solution you adopted (which is an answer to your question), you can write that in an answer.
    – apaderno
    Commented May 9, 2011 at 1:11

2 Answers 2


This issue on drupal.org might help.


If you just need to know which button has been clicked to take the necessary action, then you should assign a different submission handler to each button; see Form buttons can define custom #submit and #validate handlers for more details.
Since Drupal 6, the 'op' element in the form values, corresponding to the button clicked when there are several in a form in Drupal 5.x, should no longer be relied upon and may not be present; see what reported in The 'op' element in the form values is deprecated and should not be relied upon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.