Gossamer Forum
Home : Products : Links 2.0 : Customization :

Limit # of words in Title

Quote Reply
Limit # of words in Title
I have searched and searched for a way to limit the number of words in the Title when a link is submitted. I have found some code I thought I could butcher up but no luck yet.

What I would like to do is limit the # of words in the Title on a submit to say 4 for example. If more than 4 words the submitter would then be taken to the error page for a chance to make corrections.

Obviously I want to do this when add.cgi is called. I think.
If I can find a way to do it on the Title, I am pretty sure I can modify the code to do the same on Description.

I'm no Perl coder, but I have found I can butcher up some of the code I have found in this very helpful forum and get it to work if I have a starting place.

Thanks!
Quote Reply
Re: [EzRyder] Limit # of words in Title In reply to
These two posts will point you in the right direction, but may not be just what you want...

http://www.gossamer-threads.com/...cgi?post=73775#73775
http://www.gossamer-threads.com/...i?post=216859#216859


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Limit # of words in Title In reply to
I found those posts earlier but they seem to be dealing with a character count.
I was hoping there was a way to just count words somehow.

Thank you for the reply.
Quote Reply
Re: [PerlFlunkie] Limit # of words in Title In reply to
I did some more searching, PF you have almost done in the following code what I want to achieve. This was from a long, long time ago and shortens the description, but it does count words. I believe however this occurs in nph_build. Right now, I just can't get my head around it. If you've any ideas, I'm grateful. You offer so much help in this forum, I almost feel guilty about asking for more. Notice I said "almost"Sly

# > Abbreviated Description mod sub teaser { # -----------------------------------------------
# This creates a shortened description.
my $msg = $tease;
my $max = 6; # You can set the word count here.
my @cuts = split / /, $msg;
if ($#cuts <= $max) {
return $msg; }
else {
my $snip;
for (my $i = 0; $i < $max; $i++) {
$snip .= " ". $cuts[$i]; }
$back .= qq~...<a href="$build_detail_url/$tmp{'ID'}$build_extension">[more]</a>~; return $snip;
}
}

# < Abbreviated Description mod
$tease = $tmp{Description};
$tmp{Description} = &teaser;
# < Abbreviated Description mod