Allow textfields to be required but with fewer than 10 words
Agaric would like to be able to require the node body and other textfields but set the minimum number of words at fewer than ten– two or five.
This code from modules/node/content_types.inc, specifically line 138 ('#options' ...), would have to be changed, so that the array startes with 0, 1, 2, 5, 10 or something like that.
$form['submission']['min_word_count'] = array(
'#type' => 'select',
'#title' => t('Minimum number of words'),
'#default_value' => $type->min_word_count,
'#options' => drupal_map_assoc(array(0, 10, 25, 50, 75, 100, 125, 150, 175, 200)),
'#description' => t('The minimum number of words for the body field to be considered valid for this content type. This can be useful to rule out submissions that do not meet the site\'s standards, such as short test posts.')
);
Also, I think there may be a bug in the counting method. I don't see how or where (code below) but I had seven words in the first line (paragraph), and then subsequent paragraphs of one word each, for well over ten words total, but it still triggered the minimum words validation error.
Oh, I see the bug-- it is exploding on ' ' only-- spaces only, and so paragraph breaks are not counted, and so one-word paragraphs are not counted. Sloppy.
From node module's validation implementation, function node_validate($node, $form = array())
, on line 1973 of node.module:
// Make sure the body has the minimum number of words.
// todo use a better word counting algorithm that will work in other languages
if (isset($node->body) && count(explode(' ', $node->body)) < $type->min_word_count) {
form_set_error('body', t('The body of your @type is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@type' => $type->name)));
}
Comments
Post new comment