User login

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)));
  }

Resolution

Searched words: 
drupal body minimum number of words less than ten drupal body minimum number of words less than 10 drupal body minimum number of words drupal minimum 10 words too short

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.