0

The override function I use in my bootstrap sub-theme template.php:

function subtheme_form_titles_node_form_alter(&$form, &$form_state) {
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Activate'),   
  );
}

I use this, so I could replace a default 'Save' title of the button to 'Activate'. Funny thing is that it does replace the button title, but then when using the form and trying to save it by pressing 'Activate', nothing happens, the page just refresh, but content doesn't get created.

Also for some reason it change button class from btn-primary to btn-default. This shouldn't be happening. I just want to replace button text and keep default btn-primary class.

1

You're removing the submit handler from the element (see node_form(), towards the end). You should just change what you need to instead of replacing the whole thing:

$form['actions']['submit']['#value'] = t('Activate');

Also for some reason it change button class from btn-primary to btn-default. This shouldn't be happening.

That's not true, it should be happening. The btn-primary class is applied for submits with one of the following values:

  • 'Save'
  • 'Confirm'
  • 'Submit'
  • 'Search'
  • Correct. '$form['actions']['submit']['#attributes']['class'][] = 'btn-primary';' solved the problem. – Optimus Prime Aug 12 '14 at 10:41
  • Sorry got one of those wrong - you can either edit _bootstrap_colorize_button or add it to the form element's attribute array manually (probably easier to the second to be honest) – Clive Aug 12 '14 at 10:43
2

Your mistake is this line:

$form['actions']['submit'] = array(

It replaces original button with your own brand new array. Nothing in it, except what you put there. Original node form have submit function connected directly to a button, but you destroyed that with this line.

Instead of deleting original array and creating new one, consider simply altering values you need altered, like:

$form['actions']['submit']['#value'] = t('Activate');
  • Works, but it still change the class. – Optimus Prime Aug 12 '14 at 10:38
  • @OptimusPrime Clive's answer tells you why. But you can add class manually using #attributes. See Form API reference for details. – Mołot Aug 12 '14 at 10:40

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.