So, I've implemented hook_form_alter in a custom module. I have added a button to the node edit form of a specific content type.

However, I can't for the life of me get the new button to display with the standard buttons ie save & preview. It just appears at the top of the page, regardless of the figure that i put in as the weight (I tried 100000000000000)... Fingers crossed that this is just a 'newbie' oversight :)

Here is the code that I'm using:

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'CONTENTTYPE_node_form') {
    // Add validation for a file
        $form['field_CUSTOMFILE'][0]['#upload_validators']['custom_file_validation'] = array();

    // Add update site button to CONTENTYPE node add/edit form    
         $form['actions']['update_site'] = array(
            '#type' => 'submit',
            '#value' => 'Update site',
            '#name' => 'op',
            '#submit' => array('MYMODULE_form_submit'), /* NEED this */
            '#weight' => 99,
         $form['actions']['submit']['#weight'] = 101;
         $form['actions']['preview']['#weight'] = 100;

        return $form;



These lines from above were only added today but made no difference...

$form['actions']['submit']['#weight'] = 101;
$form['actions']['preview']['#weight'] = 100;

As always, anyway pointers would be very much appreciated :)


This question was not answered in the indicated "This question has already a answer" link above... That link explains Drupal 7 specific code, although the post isn't tagged as such... This post was specific to Drupal 6 as tagged... In fact the code in this post didn't work for me because it was using Drupal 7 code :)

  • @Mołot I have skimmed through that post, not sure how I missed it. It's all in the search i guess... That said the answer below was a pretty quick fix. I've tested the new button and the custom validation, both of which still work... Not sure what the difference is between the naming difference though ie actions vs buttons... – gMaximus Jan 8 '14 at 15:46
  • 1
    'actions' is D7, 'buttons' is D6 – Jimajamma Jan 8 '14 at 15:50
  • How did I miss that? I'm forever checking for what drupal version I'm reading about... Thanks for the clarification :) – gMaximus Jan 8 '14 at 16:01

I added a cancel button to some Drupal 6 node forms in this fashion:

  $form['buttons']['cancel'] = array(
    '#type' => 'submit',
    '#value' => t('Cancel'),
    '#weight' => 7,
    '#submit' => array('MYMODULE_node_form_cancel_submit'),

so I'd suggest changing 'actions' to 'buttons' and see if it works equally well for you.

  • Thank you ever so much! Actions and buttons hey? Dam! hours... :) – gMaximus Jan 8 '14 at 15:42
  • It's those "off by one" errors that'll get you every time :) – Jimajamma Jan 8 '14 at 15:46

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