hook_form_alter() - hands on

Event Date/Time

Fri, 3 Dec 2010 - 11:00 am - 1:00 pm
Location: 

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

Last modified Fri, 3 Dec, 2010 at 13:01