By mysocom on
Im new in module development. I tried to use annotate module example from Pro Drupal development book and I have strange error.
I can’t save Annotations per node and other settings. I can’t reset it to default. And I alwaye getting “Please enter a number.” Even if I have set number.
I made output echo “out = ”.$form_values['annotation_limit_per_node'];
But it’s empty
Glad if anybody could point out if I have configured anything wrongly.
Drupal 5.2
/**
* Define the settings form.
*/
function annotate_admin_settings() {
$form['annotate_nodetypes'] = array(
'#type' => 'checkboxes',
'#title' => t('Users may annotate these node types'),
'#options' => node_get_types('names'),
'#default_value' => variable_get('annotate_nodetypes', array('story')),
'#description' => t('A text field will be available on these node types to make user-specific notes.'),
);
$form['annotate_deletion'] = array(
'#type' => 'radios',
'#title' => t('Annotations will be deleted'),
'#description' => t('Select a method for deleting annotations.'),
'#options' => array(
t('Never'),
t('Randomly'),
t('After 30 days')
),
'#default_value' => variable_get('annotate_deletion', 0) // default to Never
);
$form['annotate_limit_per_node'] = array(
'#type' => 'textfield',
'#title' => t('Annotations per node'),
'#description' => t('Enter the maximum number of annotations allowed per node (0 for no limit).'),
'#default_value' => variable_get('annotate_limit_per_node', 1),
'#size' => 3
);
// Define a validation function.
$form['#validate'] = array(
'annotate_admin_settings_validate' => array()
);
return system_settings_form($form);
}
// Validate the settings form.
function annotate_admin_settings_validate($form_id, $form_values) {
if (!is_numeric($form_values['annotation_limit_per_node'])) {
form_set_error('annotate_limit_per_node', t('Please enter a number.'));
}
}
Comments
annotate not annotation
I've just worked through this example and spotted an error in the code. Though I'm not sure this will solve the problem you are having which I noticed also.
The last function references
'annotation_limit_per_node'where it should be'annotate_limit_per_node'There's a also a site for the book which has a useful errata section highlight many code typos and errors!
http://www.drupalbook.com/errata
PE Design
http://www.pedesign.co.uk
you are right. It should be
you are right. It should be 'annotate_limit_per_node' not 'annotation_limit_per_node'.