HOW TO AVOID BLANK SUBJECT FIELD WHEN TAB OR SPACE BAR IS HIT A FEW TIMES ?

Where in the code is the 'name' or 'subject or 'title' field validated - can someone kindly point to this ?

Best regards

Comments

misty3’s picture

Any help or link on this, please ?

Best regards

pwolanin’s picture

Interesting, the core validation for required fields doesn't apply the trim() function...

Here's the relevant function:

http://api.drupal.org/api/4.7/function/_form_validate

One easy fix: a custom validation mini module (see for general instructions: http://drupal.org/node/70903). Save as misty3_emergency.module (note: this is only very briefly tested, but should be easy to get working).

This will prevent node title from being just whitespace.

// Mini module for Drupal 4.7.x

/**
* Implementation of hook_help().
*/
function misty3_emergency_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t('custom validation- post titles cannot just be spaces or tabs.');
  }
}

/**
* Implementation of hook_nodeapi()
*
* Extra validation for the node title
*/
function misty3_emergency_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  switch ($op) {
    case 'validate':
      if (trim($node->title) == '') {
       // Disallow titles that are just whitespace
        form_set_error('title', 'You must enter some words for your title.');
      }
      break;
  }
}

---
Work: BioRAFT

pwolanin’s picture

misty3’s picture

Thanks a zillion.

This is just to say a quick thanks.

The 'trim' was in my mind but had no idea how and where to apply .............
I was trying in approx line 234 of includes/form.inc

where it is
if ($elements['#required'] && empty($elements['#value']) && $elements['#value'] !== '0')

I was guessing that trim has to go somewhere here ( and possibly it ?can ).... but had no success.

I will just try out your solution but want to say again, 'thanks'

Best regards

misty3’s picture

Hi Peter Wolanin,

I have applied the patch and it works fine.

In fact I find that this can be used with some more addition
to define the min and max words needed by the admin for
the title/subject field.

if ( (trim($node->title) == '')|| (strlen($node->title) < '4') ){
    form_set_error('title', t('The title field cannot be blank or less than 4 words'));
  }
 elseif (strlen($node->title) > '15') {
    form_set_error('title', t('The title field is too lengthy. It needs to be less than 15 words'));
  }

I was also looking for some option which can define the max allowable size in kbs for a gif /jpg.

[[ BTW , this is absolutley unrelated but since you have the gift of an excellent coder in you will it be possible
to take a look at this http://drupal.org/node/107201, which after many posts and tries , looks very weird without any solution ]]

So once again, a zillion thanks.

Best regards