10

I found a discussion with some methods for d6 here http://drupal.org/node/344802 on how to change the node "Save" button text to sg else.

Any tips for d7? I would prefer to use form api.

4 Answers 4

19

you could use string overrides module or use hook:

function yourmodule_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'name_of_form') {
    $form['actions']['submit']['#value'] = 'Your button text';
  }
}
3
  • Thanks, I only want to change it for a content type so string override is no good. I tried the form alter code but no change. I checked the $form with dpm, but it has no submit array , only a #submit which looks like sg else.
    – giorgio79
    Commented Oct 17, 2011 at 17:34
  • This worked for me. The $form_id is unique to the submit form of that content type, so it should work.
    – AndrewMRiv
    Commented Dec 14, 2016 at 20:18
  • for me it was an $form['ajax-submit']['#value'] = 'xyz', but I'm using the afb module to submit a node through a block form. Commented Aug 27, 2019 at 22:38
6

Here is an example: I have created a module called change_form_values and the form ID of my content type is content_type_test_node_form:

this work for me in Drupal 7:

function change_form_values_form_alter(&$form, &$form_state, $form_id) {
    //dsm($form_id); // to see form ID
    if ($form_id == "content_type_test_node_form") {
    $form['actions']['submit']['#value'] = 'New button text';
    }
}

this work for me in Drupal 6:

function change_form_values_form_alter(&$form, &$form_state, $form_id) {
    //dsm($form['form_id']['#id']);
    if ($form_id == "content_type_test_node_form") {
    $form['buttons']['submit']['#value'] = 'New button text';
    }
}

I hope information be useful.

0

I found the excellent Node buttons edit module for this and it works really our of the box using admin. Here is an excerpt about it from the module's project page:

This is a simple little module that allows one to change the text on the 'Save', 'Preview' and 'Delete' buttons on a node form.

0

For Drupal7 it's simple just:

$form['buttons'] = array(
    '#type' => 'submit',
    '#value' => t('Your desire text here'),
    );

Wihtout adicional functions...

2
  • Nah, by that you'ld overwrite the whole button and reset possible other values given originally (#weight, #validate, #submit ...). You'ld better go only for the #value, like written in the other answers above.
    – leymannx
    Commented Mar 16, 2016 at 9:10
  • i tested with 3 form of my site and all of them are working fine... i guess what you said could be possible if your using some kind of callback function or ajax function related to the button.... Commented Mar 16, 2016 at 16:40

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.