• : Function ereg() is deprecated in /home/starbowc/drupal6/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/starbowc/drupal6/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/starbowc/drupal6/includes/file.inc on line 895.

Example from Intro to Module Development Presentation

Here is the code from module I used as the working example in my "Intro to Module Development" presentation at BADCamp today. This is just a quick example of how to modify a Drupal form. It adds buttons at the top of your node edit form. I also showed off my Input Format Manger module, available at: http://drupal.org/project/format_manager

top_buttons.info

; $Id:$
name = Top Buttons
description = Add extra Save, Preview and Delete buttons at the top of the node save form
core = 6.x
package = User interface

top_buttons.module

<?php
// $Id$

/**
* @file
* top_buttons.module
*
* Modify the node save form to add Save & Preview buttons at the top.
*/

/**
* Implementation of hook_form_alter.
*
* @param $form - form array
* @param $form_state - array with form state info
* @param $form_id - name of the form
* @return modified form array
*/

function top_buttons_form_alter(&$form, $form_state, $form_id) {
  if (
strrpos($form_id, 'node_form') === strlen($form_id) - strlen('node_form')) { // Ends with.
   
$form['top_submit'] = array(
     
'#type' => 'submit',
     
'#access' => !variable_get('node_preview', 0) || (!form_get_errors() && isset($form_state['node_preview'])),
     
'#value' => t('Top Save'),
     
'#weight' => -10,
     
'#submit' => array('node_form_submit'),
    );
   
$form['top_preview'] = array(
     
'#type' => 'submit',
     
'#value' => t('Top Preview'),
     
'#weight' => -9,
     
'#submit' => array('node_form_build_preview'),
    );
   
$node = $form['#node'];
    if (!empty(
$node->nid) && node_access('delete', $node)) {
     
$form['top_delete'] = array(
       
'#type' => 'submit',
       
'#value' => t('Top Delete'),
       
'#weight' => -8,
       
'#submit' => array('node_form_delete_submit'),
      );
    }
  } 
 
}
?>

buttons only on the preview page?

Thanks for this - I've been trying to figure this out for a while. However, I really want to limit the buttons on the top of the form to the node preview screen. In that way a user would be forced to preview the first node submission and then below the node preview they would be presented with a submit button so they don't have to scroll through the form again. If you could recommend something I'd really appreciate it.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.