Closed (fixed)
Project:
Field Validation
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
2 Nov 2011 at 07:46 UTC
Updated:
8 Apr 2012 at 15:30 UTC
Using word validation limit of 500, I pasted in 500 words into WYSIWYG editor, TinyMCE, and it's word count was 500. On save the field validator kicked in with a warning. I had to reduce this to about 488 before it passed the 500 word limit.
Here's an example code that we have used in the past to do similar validation, not the most efficient but it works and may help.
$value = $form_state['values']['body'];
$count = count(explode(' ', trim(preg_replace('/\s+/', ' ', str_replace(' ', ' ', (strip_tags(str_replace('<', ' <', $value))))))));
if ($count > 60) {
form_set_error('body', t('Description must be less than 60 words. Current length is '. $count), $form_state);
}
Comments
Comment #1
g089h515r806 commentedI just copy the logic from webform validation. we need more preprocess before validation.
Comment #2
g089h515r806 commentedI have copy your logic code into the latest dev version.