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.
Comment | File | Size | Author |
---|---|---|---|
#4 | 1354596.op-to-array-parents.patch | 2.1 KB | rszrama |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe should use triggering element here.
Comment #2
pcambraAll of these were replaced in #1059402: Replace $form_state['clicked_button'] with $form_state['triggering_element']
Comment #3
magicmyth CreditAttribution: magicmyth commentedThat issue deals with the change of 'clicked_button' to 'triggering_element'. Not the use of 'op' from the standard 'submit' type.
Comment #4
rszrama CreditAttribution: rszrama commentedLetting the test bot run through this. Basically, I'm changing our checks against
$form_state['values']['op']
to checks againstend($form_state['triggering_element']['#array_parents'])
. Worked fine in my browser testing.Comment #5
rszrama CreditAttribution: rszrama commentedCommitted.
Comment #6
magicmyth CreditAttribution: magicmyth commentedThanks 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
Comment #7
rszrama CreditAttribution: rszrama commentedThanks, Adam. And yep, the Add Payment button just needed the same fix. : )