Currently Commerce checkout module in commerce_checkout.pages.inc line 230 does the following comparison to determine if the Checkout button was clicked:

if ($form_state['values']['op'] == $form_state['values']['continue'])

This will always fail if the button is changed to an image (#type = 'image_button') because the traditional Drupal 'op' method of checking clicked buttons will not work with image_buttons. Instead every button should have a unique form field name and checkout should then use 'triggering_element' to determine what button was clicked. This will work with all button types (including image_button when configured correctly (remember to remove #value and set #return_value)).

Because switching to using triggering_element may break existing modules expecting to check for 'op' I've used a workaround just before:

// If the form was submitted via the continue button...
if ($form_state['values']['op'] == $form_state['values']['continue']) {

Which is:

  // HACK Workaround form image_button
  if ($form_state['triggering_element']['#type'] == 'image_button') {
    $form_state['values']['op'] = $form_state['triggering_element']['#value'];
  }
  // If the form was submitted via the continue button...
  if ($form_state['values']['op'] == $form_state['values']['continue']) {

And my continue button in each of the panel hook_form_alters:

    $form['buttons']['continue']['#type'] = 'image_button';
    $form['buttons']['continue']['#alt'] = 'Continue';
    $form['buttons']['continue']['#return_value'] = $form['buttons']['continue']['#value'];
    unset($form['buttons']['continue']['#value']);
    $form['buttons']['continue']['#name'] = 'continue';
    $form['buttons']['continue']['#button_type'] = 'submit';
    $form['buttons']['continue']['#input'] = TRUE;
    $form['buttons']['continue']['#src'] = _THEME_DIR.'/images/buttons/btn-arrow-right-01.png';
    $form['buttons']['continue']['#weight'] = 1;

This allows the checkout pane navigation buttons (Cancel, previous, continue) to use images and keeps the client happy ;)

I don't think this is actually specific to the Checkout module but I've only checked there so far. Cart update form does not have this issue when I changed its buttons to images but I think an issue may exist with the "Add to cart" button. I've not verified though so setting component to Checkout for now.

CommentFileSizeAuthor
#4 1354596.op-to-array-parents.patch2.1 KBrszrama

Comments

damien tournoud’s picture

We should use triggering element here.

pcambra’s picture

magicmyth’s picture

That issue deals with the change of 'clicked_button' to 'triggering_element'. Not the use of 'op' from the standard 'submit' type.

rszrama’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new2.1 KB

Letting the test bot run through this. Basically, I'm changing our checks against $form_state['values']['op'] to checks against end($form_state['triggering_element']['#array_parents']). Worked fine in my browser testing.

rszrama’s picture

Status: Needs review » Fixed

Committed.

magicmyth’s picture

Thanks rszrama. I've tested the patch and all seems good with image buttons. FYI I see you also made a change to the Add Payment button but I did not test that. I'll just assume if I change that to an image it will work as well.

Nice solution.

Adam

rszrama’s picture

Thanks, Adam. And yep, the Add Payment button just needed the same fix. : )

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.