Let's create a folder called sites/all/modules/mysite and build a bare-bones mysite.info file using the text editor of your choice.
name = My Site
description = Provides custom functionality for this site
core = 6.x
project = "mysite"
package = Other
If we simply created a skeleton mysite.module file, we could already enable our new module, although it wouldn't do anything until we actually added some code to it. The actual act of creating a module is that simple. But let's go ahead and create our form altering module, and then I'll explain it.
<?php
// $Id$
/**
* @file
* Drupal Module: mysite
* Adds custom code specific to this Drupal 6 site.
*/
/**
* Implementation of hook_form_alter().
*/
function mysite_form_alter(&$form, &$form_state, $form_id) {
// print $form_id;
switch ($form_id) {
case 'blog_node_form':
// remove some unwanted node editing fields
$form['revision_information']['#access'] = 0;
$form['menu']['#access'] = 0;
$form['author']['#access'] = 0;
// override node options permissions defined by 'administer nodes'
$form['options']['#access'] = 1;
$form['options']['status']['#access'] = 1;
$form['options']['promote']['#access'] = 0;
$form['options']['sticky']['#access'] = 0;
break;
case 'page_node_form':
// don't ever allow page nodes to be promoted or sticky
$form['options']['promote']['#access'] = 0;
$form['options']['sticky']['#access'] = 0;
break;
}
}
The comment section at the top is not required, but you should include this to stay consistent with Drupal coding standards.
To implement hook_form_alter, simply create a function called modulename_form_alter, using the parameters shown. Drupal will automatically use this function if it exists in your module.
If you're not sure which form you're altering, uncomment the print $form_id line, and form names will appear at the top of your page. (Remove this line in production environments, of course!)
Notice that we're mostly just ripping out sections of the form. Removing the author section does not work well, however, because it makes all nodes authored by the anonymous user. By disabling the author section of the form, I'm removing the ability to override authorship information even for users who would normally be allowed to do so, like the site administrator.
That's all there is to it, but you may be wondering how I know what values to manipulate. Add the following section of code after (or replacing) the unset commands, and you'll see:
$form['form_array'] = array(
'#value' => '
'. print_r($form, 1) .'
',
'#weight' => '99',
);
This piece of code adds a new element, called form_array to the form. It will spit out a big ugly hunk of preformatted text at the end of your node edit form, showing all of the existing form elements, any of which can be altered.
So go ahead and create this simple module on a test site, and have fun. With even a basic understanding of php syntax, you'll be tweaking up those input forms in no time, and your users will love you for removing all of those confusing fields they don't need to see.
cegonsoft