Errata (Second Edition)
This page lists the errors found in the book.
Chapter 10. The Form API, Page 224
Mon, 10/06/2008 - 7:12pm — gpkThe element_info() hook
The _element_info() function
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
Mon, 10/06/2008 - 7:21pm — gpkA 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:
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:
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
Wed, 02/18/2009 - 11:10pm — rfayLast sentence of paragraph: "Returning FALSE from the final submit funciton avoids redirection."
Delete sentence
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
Thu, 06/11/2009 - 5:10pm — nimrod98function formexample_nameform_submit($form_id, $form_state) {
It should be:
function formexample_nameform_submit($form_id, $form_state) {
There was a change in the variables passed, compare it to page 230, last paragraph function.
Chapter 10. The Form API, Page 237
Thu, 06/11/2009 - 6:01pm — nimrod98$form['blinky'] = array(
'#type' = 'markup',
'#value' = 'Hello!'
);
$form['blinky'] = array(
'#type' => 'markup',
'#value' =>'Hello!'
);
The '#type' should be an arrow pointing to 'markup'; not an '=' sign
Chapter 10. The Form API, Page 240
Thu, 02/19/2009 - 9:18am — jvandykfunction formexample_nameform_validate($form, $form_state) {
function formexample_nameform_validate($form, &$form_state) {
Pass $form_state by reference so that a form_set_value() call would work.
Chapter 10. The Form API, Page 242
Wed, 03/18/2009 - 7:54am — jvandyk$my_data = $form_values['my_placeholder'];
$my_data = $form_state['values']['my_placeholder'];
In Drupal 6, form values are available within a submit function as $form_state['values'].
Chapter 10. The Form API, Page 244
Tue, 08/19/2008 - 12:48pm — jvandykfunction formexample_nameform($form_id, $form_state = NULL) {
function formexample_nameform($form_state) {
Drupal 6 always passes the form state as the first argument to form builder functions.
Chapter 10. The Form API, Page 244
Thu, 02/19/2009 - 12:42am — rfayThe signature of the called function is incorrect. This is also incorrect throughout the downloadable code for this chapter.
The correct signature is
function formexample_nameform($form_state=NULL)
$form_state is passed in the first parameter.
$form_state is passed in the first parameter, not the second.
Chapter 10. The Form API, Page 248
Sun, 05/30/2010 - 8:05am — wdrupalfunction 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'),
);
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'),
);
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.
