3

Looking at the source of a module, it is doing this:

$form['buttons']['back'] = array(
  '#prefix' => t('or'),
);

Now I want to remove that prefix; I tried the following code, but it doesn't make any difference.

function mymodule_form_formid_alter(&$form, &$form_state) {
  $form['buttons']['back']['#prefix'] = ''; 
}

I tested the following code, but it doesn't seems to work; the prefix is now 'testingor'.

function mymodule_form_formid_alter(&$form, &$form_state) {
  $form['buttons']['back']['#prefix'] = 'testing'; 
}

I tried the following code, but it doesn't make any difference.

function mymodule_form_formid_alter(&$form, &$form_state) {
  unset($form['buttons']['back']['#prefix']) ; 
}

What am I doing wrong?

The form ID for the form I am trying to change is "commerce_checkout_form_checkout" which is used from the Drupal Commerce module.

8
  • Have you see if the form has a theme function ? Its can be inside. Or give us the name of module if its contrib module.
    – yvan
    Commented Sep 20, 2011 at 15:33
  • 2
    It could be a module weight issue. By default, functions of the same hook are called in alphabetical order of the module that define them. If your module runs before the commerce module, it would override your changes. Commented Sep 20, 2011 at 15:52
  • Thanks. I tried setting the weight of my module higher than the commerce modules, but it made no difference. Seems odd.
    – pushka
    Commented Sep 23, 2011 at 18:52
  • 3
    Make sure you are using the correct formid, by adding some debug code (drupal_set_message("I'm alive!")) to the form alter hook. Also remember to clear the caches after creating a new hook.
    – Berdir
    Commented Oct 4, 2011 at 2:03
  • Thanks. In the second test I described where I added the prefix 'testing', I think this confirms I have the correct formid? But I could be wrong...
    – pushka
    Commented Oct 5, 2011 at 8:15

1 Answer 1

1

In your hook_form_alter the following should do the job and has the benefit of leaving the element there if required.

$form['buttons']['back']['#access'] = false;
1
  • 1
    That is quiet excessive, for somebody who just wants to alter the prefix shown for a field. The OP doesn't want to hide the button.
    – avpaderno
    Commented Apr 13, 2012 at 11:16

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.