CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
character count in a form

 



jasan
Deleted

Apr 25, 2001, 3:21 AM

Post #1 of 5 (867 views)
character count in a form Can't Post

I need a way to keep a check on the number of characters typed in an online form textfield. maximum number is 160 (client is using a service to send text messages to cell phone) Maybe this should be javascript ? I'm a designer so please keep advice as non techie as possible!!! Thanks



James
Troll

Apr 25, 2001, 11:19 AM

Post #2 of 5 (862 views)
Re: character count in a form [In reply to] Can't Post

Just add the MAXLENGTH attribute to your INPUT tag:


Code
<INPUT TYPE="text" NAME="name" MAXLENGTH=160>



(This post was edited by James on Apr 25, 2001, 10:20 AM)


jasan
Deleted

Apr 26, 2001, 1:59 AM

Post #3 of 5 (857 views)
Re: character count in a form [In reply to] Can't Post

Thanks James, appreciate the reply. I eventually found a javascript that keeps a running total of the characters as you type and limits max length too. (javascript.com)
Jason



James
Troll

Apr 26, 2001, 8:32 AM

Post #4 of 5 (855 views)
Re: character count in a form [In reply to] Can't Post

I may not have understood exactly what you were after, but here's another 2 cents anyway.

The problem with javascript is that a lot of people (like me) leave it disabled by default. Unless that disables your entire form, my browser would ignore any javascript commands.

If you just want to limit the length of the input, I think MAXLENGTH is the best way to go. If you need to keep a running character count, then javascript is probably your best (or only) choice. I don't think there's any reason why you couldn't use both in combination -- that should cover you in all situations.



Jasmine
Administrator

Apr 26, 2001, 9:09 AM

Post #5 of 5 (854 views)
Re: character count in a form [In reply to] Can't Post

Both of the above will work on the form display end (one assuming js is enabled), but neither will stop someone from saving the form locally, stripping the limitations, and entering a thousand characters. Two suggestions:

1) Make sure you check the referrer of the form submission. If it's not from your domain, then don't accept it.

2) Check and/or shorten the string at the form processing end.


Code
if ( length $message > 160 ){ 

my $trunc = substr( $message, 0, 160 );

print <<EOF;
Your input is too long and has been truncated to :
$trunc
If you don't like it, try again.
EOF

}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives