0

I need to add a custom function to the Confirm Order button on a Commerce Checkout form. I can't figure out how to call it. The button id is "#edit-continue' and its displayed text is 'Confirm Order'. I -thought- this would show up in the $form[submit] array, but that array is empty. So I checked $form['buttons']['continue']['#submit'] and this seems to be where Commerce stores the submit functions.

I created a module and two functions

function MYMODULE_form_commerce_checkout_form_checkout_alter($form, $form_state, $form_id){ 
   drupal_set_message('ALTERING CHECKING OUT! THIS WORKS' . $form_id);   
   $form['buttons']['continue']['#value'] = 'Send Me A Quote!';
   $form['buttons']['continue']['#submit'][] = 'MYMODULE_submit';       

...and then I have this function:

function MYMODULE_submit_function($form, &$form_state) {
  die('Triggered submit');
}

...So the message() function displays (good) but the submit function does not fire and the text in the button is not altered (bad.) So clearly, the problem is that I am not targeting the button properly. How do I 'address' that button?

BTW: Not to be obvious, but I need to overload that button, not -replace- the commerce checkout functionality.

I realise that displays of emotion are pointless, but...

HEEEEEEEELLLLP!

PS: I have no access to the console or Devel. So I'm kinda limited as to my tools for debugging to var_dump()

Ideas?

0

You must be using hook form alter so do a dpm($form) before adding the custom function to the submit handler and then do dpm($form) again after adding your custom handler and see if it shows your custom handler over there or not. dpm() will work if you have devel module installed otherwise do a var_dump() instead of dpm(), debugging the code should take you to the answer.

  • I don't have Devel installed. I did a var_dump() on the $form array and the 'Confirm' button is in the ['buttons'] section. I added this above. Any ideas? – jchwebdev Jun 8 '13 at 17:25
  • Also... another possible noob question: why doesn't the #ID attribute of the button match anything in the $form array? – jchwebdev Jun 8 '13 at 22:26
0

Your changes to $form here are lost because you are passing by value. Pass by reference using &$form instead:

function MYMODULE_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
0

Based solely on the code you gave above, you've got at least one glaring issue. This code is okay:

function MYMODULE_form_commerce_checkout_form_checkout_alter($form, $form_state, $form_id){ 
   drupal_set_message('ALTERING CHECKING OUT! THIS WORKS' . $form_id);   
   $form['buttons']['continue']['#value'] = 'Send Me A Quote!';
   $form['buttons']['continue']['#submit'][] = 'MYMODULE_submit';  

However, in this block:

function MYMODULE_submit_function($form, &$form_state) {
  die('Triggered submit');
}

MYMODULE_submit_function should actually be the same as the handler you added in the form alter (i.e. MYMODULE_submit without the _function).

It's looking for that exact function name and won't add anything else to it like it does with the other form submit handlers that are called in drupal_get_form().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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