Errata (Second Edition)

This page lists the errors found in the book.

Chapter 10. The Form API, Page 224

Location on the page: 
Bottom of page
Chapter: 
10. The Form API
Error: 

The element_info() hook

Correction: 

The _element_info() function

Description of the Error: 

Wrong function name; also, it is not a hook. See http://api.drupal.org/api/function/_element_info/6 for API documentation of this function.

Chapter 10. The Form API, Page 225

Location on the page: 
Section "Looking for a Validation Function" (first paragraph on page)
Chapter: 
10. The Form API
Error: 

A validation function for a form can be assigned by setting the #validate property in the form to an array with the function name as the key and an array as the value. Anything that appears in the latter array will be passed to the function when it is called. Multiple validators may be defined in this way:

Correction: 

A validation function for a form can be assigned by setting the #validate property in the form to an array with the function name as the value. Multiple validators may be defined in this way:

Description of the Error: 

In Drupal 6.x, the #validate property only specifies the name(s) of the validate handler(s). The syntax in which arguments for the validate handler are defined within the #validate property applies to Drupal 5.x.

Chapter 10. The Form API, Page 228

Location on the page: 
Bottom paragraph "Redirecting the User"
Chapter: 
10. The Form API
Error: 

Last sentence of paragraph: "Returning FALSE from the final submit funciton avoids redirection."

Correction: 

Delete sentence

Description of the Error: 

Redirection always occurs after the final submiit. Depending on the #submit value, it may go to a different page, but there is always a redirect at this point.

Chapter 10. The Form API, Page 234

Location on the page: 
In the function formexample_nameform_submit()
Chapter: 
10. The Form API
Error: 

function formexample_nameform_submit($form_id, $form_state) {

Correction: 

It should be:
function formexample_nameform_submit($form_id, $form_state) {

Description of the Error: 

There was a change in the variables passed, compare it to page 230, last paragraph function.

Chapter 10. The Form API, Page 237

Location on the page: 
Top of page, $form['blinky']
Chapter: 
10. The Form API
Error: 

$form['blinky'] = array(
'#type' = 'markup',
'#value' = 'Hello!'
);

Correction: 

$form['blinky'] = array(
'#type' => 'markup',
'#value' =>'Hello!'
);

Description of the Error: 

The '#type' should be an arrow pointing to 'markup'; not an '=' sign

Chapter 10. The Form API, Page 240

Location on the page: 
bottom
Chapter: 
10. The Form API
Error: 

function formexample_nameform_validate($form, $form_state) {

Correction: 

function formexample_nameform_validate($form, &$form_state) {

Description of the Error: 

Pass $form_state by reference so that a form_set_value() call would work.

Chapter 10. The Form API, Page 242

Location on the page: 
Middle
Chapter: 
10. The Form API
Error: 

$my_data = $form_values['my_placeholder'];

Correction: 

$my_data = $form_state['values']['my_placeholder'];

Description of the Error: 

In Drupal 6, form values are available within a submit function as $form_state['values'].

Chapter 10. The Form API, Page 244

Location on the page: 
Code example at bottom of page
Chapter: 
10. The Form API
Error: 

function formexample_nameform($form_id, $form_state = NULL) {

Correction: 

function formexample_nameform($form_state) {

Description of the Error: 

Drupal 6 always passes the form state as the first argument to form builder functions.

Chapter 10. The Form API, Page 244

Location on the page: 
Final blockof code, beginning function formexample_nameform(
Chapter: 
10. The Form API
Error: 

The signature of the called function is incorrect. This is also incorrect throughout the downloadable code for this chapter.

Correction: 

The correct signature is
function formexample_nameform($form_state=NULL)

$form_state is passed in the first parameter.

Description of the Error: 

$form_state is passed in the first parameter, not the second.

Chapter 10. The Form API, Page 248

Location on the page: 
Code snippet at the top
Chapter: 
10. The Form API
Error: 

function formwizard_menu() {
$items['formwizard'] = array(
'title' => t('Form Wizard'),
'page callback' => 'drupal_get_form',
'page arguments' => array('formwizard_multiform'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access content'),
);
$items['formwizard/thanks'] = array(
'title' => t('Thanks!'),
'page callback' => 'formwizard_thanks',
'type' => MENU_CALLBACK,
'access arguments' => array('access_content'),
);

Correction: 

function formwizard_menu() {
$items['formwizard'] = array(
'title' => 'Form Wizard',
'page callback' => 'drupal_get_form',
'page arguments' => array('formwizard_multiform'),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('access content'),
);
$items['formwizard/thanks'] = array(
'title' => 'Thanks!',
'page callback' => 'formwizard_thanks',
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);

Description of the Error: 

As stated on page 71 ("Title Localization and Customization"), the t()-function shall not be used in menu item titles or descriptions. Also, note the mistaken use of 'access_content' instead of 'access content' in the access arguments declaration.