How To Instigate a Word Limit?
mwsmedia - March 1, 2005 - 07:14
I'm interested in placing a word limit in a node entry ... perhaps by utilizing flexinode. Essentially, I want users to write an entry that can be no longer than 750 words (or perhaps 4,000 characters.)
Does anyone have any ideas on how to make this work?
Many thanks,
Matt

Examples
Hi,
This is really easy. Have a look at how for example blog module handles its minimal word count. IT is really easy to use that code in a flexinode, with little change to suit maximum word count.
Note, however, that drupal supports a lot of languages that have no clear word boudries, such as Japanese.
And if this solved you problem, would you be so kind to report back that it helped? This will help others whom are looking for the same solution.
[Ber | Drupal Services webschuur.com]
Cut n Paste
I'll give that a try, Ber... I'm not much of a coder, but if it's a cut and paste kind of thing, I can probably manage it.
I wonder how tough it would be to add a little thing that lets the poster know how many words they have left, real time? I've seen these, but my ability to instigate it might be a stopping block.
Thanks for the advice!
Matthew Wayne Selznick
MWS Media
http://www.mwsmedia.com
Where Doing It Yourself
Never Means Going It Alone
Beyond Me
Urrr... I just don't understand PHP well enough to hack Drupal. I'm a user, not a developer... I can drive a car, but I can't build one, you know?
If anyone is interested in creating a version of flexinode that allows word limits in the node, I'd be very grateful, and credit you and your work on my site.
Thanks,
Matthew Wayne Selznick
MWS Media
http://www.mwsmedia.com
Where Doing It Yourself
Never Means Going It Alone
I wanted to do the same
I wanted to do the same thing, but I couldn't find anything in the blog module and I have a very limited knowledge of php. So what I did, was limit the final output. This means that if a user enters a description field (in my case) longer than 20 words, only the first 20 will show. This poses various problems (and is not a solution to your problem, nor mine), but is a start. If I can find a way to cut the string in a '.', I would be reasonably happy.
anyway I created node-flexinode-1.tpl.php in my theme folder and is something like this.
<?php
// Generate CSS classes for the node
$classes = array();
if ($sticky)
$classes[] = 'sticky';
if (!$page) {
$classes[] = 'item-listing';
$classes[] = $zebra;
$classes[] = "node-list-$seqid";
}
$classes = ' ' . implode(' ', $classes);
?>
<div class="node<?php print $classes; ?>">
<?php if ($picture) print $picture; ?>
<?php if (!$page) { ?><h2 class="title"><a href="<?php print $node_url?>" title="<?php print $title?>" rel="bookmark"><?p
hp print $title?></a></h2><?php }; ?>
<div class="info">
<?php if ($submitted) { ?>
<span class="submitted">
<span class="user"><?php print theme('username', $node); ?></span> -
<span class="date"><?php print format_date($node->created, $type="large"); ?></span>
</span>
<?php } ?>
<?php if ($terms) { ?> <span class="taxonomy">Tags: <?php print $terms?></span> <?php } ?>
</div>
<div class="content">
<?php
//assign description text to variable for trimming
$mytext=$node->flexinode_2;
$n=20; //word limit
$validated= implode(" ", array_slice(preg_split("/\s+/", $mytext), 0, $n));
?>
<div id="special_content">
<?php if ($node->flexinode_1):?><div id="flexifield_one"><br><strong> Name:</strong><br><?php print $node->flexinode_1 ?><br> </div><?php endif;?>
<?php if ($node->flexinode_2):?><div id="flexifield_two"><br><strong> Description:</strong><br><?php print $validated; ?><br> </div><?php endif;?>
<?php if ($node->flexinode_9):?><div id="flexifield_three"><br><strong> Address:</strong><br><?php print $node->flexinode_9 ?><br> </div><?php endif;?>
<?php if ($node->flexinode_3):?><div id="flexifield_four"><br><strong> Telephone:</strong><br><?php print $node->flexinode_3 ?><br> </div><?php endif;?>
</div>
</div>
<?php if ($links) { ?><div class="links">» <?php print $links?></div><?php } ?>
<div class="clear"></div>
</div>
Hope it helps a bit
It has been some time since
It has been some time since this topic was published, but I'm having the same problem. Is there a way to set a maximum on the number of words of a text area in flexi-node? I've searched the site, but haven't found an answer. I also found this topic: http://drupal.org/node/91368 , but there hasn't been a reply yet.
Managed to instigate a word limit
Hi,
I've been scratching my head over this one for a while but finally managed to instigate a 49-word limit on my site: http://49words.com. Try it out if you'd like to see how it's working.
I'm using drupal 5.1 with a custom CCK type.
If anybody is still interested I can dig through my code and pull out how I did it. Basically, I'm using jquery for javascript enabled browsers to show the word count beneath the node entry form, and form validation using a tweaked maxlenghth module. The word limt also works for comments BTW.
It's been some time since this one was discussed but if anybody's interested let me know and I'll publish my method.
Thanks, pete
Count me in
I'd certianly love to learn how you implemented this. And how you got the maxlength module to work; it throws watchdog errors for me. :(
Thanks in advance for sharing.
Carey
Maxlength for custom fields
Hi everyone,
Just giving back to the community. If you want maxlength on a custom field, you can hack the maxlength module (yeah it's dirty, but seems to work)
I needed a maxlength for a textarea called "review_text" , so I browsed the maxlength code and found :
function theme_maxlength_textarea($element) {
$prefix = '';
if ($element['#name'] == 'body') {
$path = drupal_get_path('module', 'maxlength');
drupal_add_js($path . '/maxlength.js');
if (arg(1) == 'add') {
$type = arg(2);
}
else
{
...etc... etc....
Where the line to look for is :
if ($element['#name'] == 'body') {And then change "body" for the field in the DB that needs the maxlength, I had to use "review_text" :
if ($element['#name'] == 'review_text') {If you want both to still work, I guess this should do it :
if ($element['#name'] == 'body' || $element['#name'] == 'review_text') {Hopefully this helps someone.
ready module
http://drupal.org/project/maxlength.
Work great for me.
-najibx-
only characters, not words
Ah yes, but maxlength only allows for a maximum number of characters
. There is a big difference between number of characters and number of words--many places require word counts as a matter of course.-jj