Drupal: customize forms

Drupal forms are arrays which are eventually converted to HTML. The easiest way to customize a form is to modifify its array before it's rendered to HTML, using hook_form_alter().

/**
* Implementation of hook_form_alter().
*
* This lets you make changes to any form in the site. You can alter, remove
* or add form elements. You can also alter the validation and submission
* behavior. The name will always be modulename_form_alter.
*/
function module_form_alter(&$form, $form_state, $form_id) {
	//print_r($form);
 
	switch ($form_id) {
		case 'page_node_form':
			// menu: expand by default
			$form['menu']['#collapsed'] = 0;	
 
			// menu: weight: better explanation
			$form['menu']['weight']['#description'] = 'Items with a small weight will appear first.'; 
 
			// body: "Split sumamry at the cursor" button: hide
			$form['body_field']['teaser_include']['#access'] = FALSE;
 
			// preview button: hide
			unset($form['buttons']['preview']);
 
			break;
 
		case 'custom_type_node_form':
			// ...
			break;
 
	}

Uncomment print_r($form) to display the form array in your browser so you can find the form id and have a look at the array structure.

Feedback