Skip to content Skip to navigation

hook_form_alter() - hands on

December 2, 2010 - 4:00pm
Stanford Law School, rm 283

Notes from the MoC

function mymodule_form_page_node_form_alter has to be in the module - not in template.php

Module forminspect can be used to get form info (press view releases to download this module)

Two main hooks are hook_form_alter and hook_form_FORM_ID_alter

Example [unset Preview Button]

function mymodule_form_alter(&$form, &$form_state, $form_id){

if ( $form_id == 'page_node_form' ) { unset ( $form['buttons']['preview'] ); }

function mymodule_form_page_node_form_alter(&$form, &$form_state){ unset ( $form['buttons']['preview'] ); }

Other modules can overwrite form ids (for example Profile module overwrites User registration form), so module Util can be used to set module's order