THE DISCUSSION BOARD OF VITINH.DE
  Free Perl Guestbook - F.A.Q
  Message Character Limit

Post New Topic  Post A Reply
edit profile | register | preferences | faq | members list |

Email this page to your friend! next newest topic | next oldest topic
Author Topic:   Message Character Limit
Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 10-08-2010 20:13     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
There's already the ability to set the maximum character length for the message submitted, however, how about showing the maximum and amount of characters left under the textarea box on the entry page.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 12-08-2010 11:55     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Excellent suggestion! I hope that Tri will find time to implement it.

Sadly though, given the looks of this messageboard, it appears that FPG hasn't received much attention lately.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 12-08-2010 15:31     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
This solution appears to be ideal: http://www.smartwebby.com/DHTML/textbox_characters_counter.asp

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 21-08-2010 08:16     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Hello Highlander,

Thanks for the code snippets, but I am not quite sure how to implement it with FreePerlGuestbook.

Would I be correct to assume that the javascript code needs to go in the head section of the "sign.tpl", while the HTML code goes in the actual guestbook.cgi file, possibly between lines 2964-2966?

Can you please show me how you have implemented it in your copy of FPG?

Thanks so much!

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 21-08-2010 18:52     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Highlander,

I got the character count code working with a separate HTML test form page that I made on my server -- using a simple perl form cgi -- but I still haven't figured out how to actually implement the code in FPG.

While I know where the various textareas are located in the FPG cgi script, and have assumed that the javascript should probably go in the head of the sign.tpl file, my problem is that I still haven't figured out where to place the HTML part of the code in the actual FPG cgi script.

Any help would be greatly appreciated.

Thanks!

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 24-08-2010 04:13     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Highlander,

Please disregard all of my previous messages. I finally got that character counter code working properly in FPG. As you probably know, some of the code had to be placed in the actual cgi itself, while the javascript itself had to go in the sign template, along with some extra HTML text.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 24-08-2010 14:27     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
Hi WordWeaver

I've been meaning to reply but time was against me. I'm not a perl coder and its a bit daunting experimenting with the cgi script file although I did remove some coding which set the background colour to white in tables which was overiding custom colours I applied to admin files.

I'd very much like to see your Guestbook and how and where to place the javascript and html although the latter I probably know.

Thanks for your time and effort.

[This message has been edited by Highlander (edited 24-08-2010).]

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 24-08-2010 14:28     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
i duplicated my posting by mistake, we cant delete posts?

[This message has been edited by Highlander (edited 24-08-2010).]

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 25-08-2010 05:40     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Hello again Highlander. Well, I am not a PERL programmer either, and I had pretty much given up on trying to figure out how to implement the code. However, if there is one thing about me, it is that I don't like to be defeated by this technology. So, yesterday morning, I made one final attempt to figure it out . . . and thankfully, I did. It was a bit tricky, because of the way that Tri has the textarea written in the cgi file, but once I located it, I had it all figured out within a few minutes . . . after working on it on and off for those few days.

Anyway, if you are interested:

http://www.endtimeprophecy.net/cgi-bin/EPNguestbook/EPNguestbook.cgi

If you like the way the code looks and works in my guestbook, I will be more than happy to share it with you.

[This message has been edited by WordWeaver (edited 25-08-2010).]

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 26-08-2010 07:18     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
HOW TO USE THE CHARACTER COUNTER CODE WITH FPG


1. In the "fpg.cgi" file change line 738 . . .

From this . . .

$input = "<textarea name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";

To this . . .

$input = "<textarea onKeyPress=\"return taLimit(this)\" onKeyUp=\"return taCount(this,'myCounter')\" name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";


2. In the "sign.tpl" file, add the following javascript code to the "head" section of the file:

<script language="Javascript" type="text/javascript">
/**
* DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/

maxL=2000;
var bName = navigator.appName;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}

function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
</script>

IMPORTANT: Make sure that you edit the "maxL=2000;" string so that it matches whatever character limit value you have set in FPG's prefs in the Admin section.


3. Further down in the same "sign.tpl" file, find this . . .

<td valign="top" bgcolor="#F0F0F0">
$$FPG_CODES$$<!-- Don't remove this line -->
$$FPG_CODES_OPTION$$<!-- Don't remove this line -->
$$FPG_MESSAGE$$<!-- Don't remove this line --><br>
$$FPG_SMILEYS$$<!-- Don't remove this line -->
</td>

And change it to this . . .

<td valign="top" bgcolor="#F0F0F0">
$$FPG_CODES$$<!-- Don't remove this line -->
$$FPG_CODES_OPTION$$<!-- Don't remove this line -->
Max. Num. Of Chars = 2000 <span id="myCounter">2000</span> Characters Left<br>
$$FPG_MESSAGE$$<!-- Don't remove this line --><br>
$$FPG_SMILEYS$$<!-- Don't remove this line -->
</td>

IMPORTANT: Don't forget to set the character value in BOTH places in that new string, so that they match whatever character limit value you have set in FPG's prefs in the Admin section.


4. That's it. Save the "sign.tpl" file and you are done. Naturally, because you are smart, you will save backup copies of both the altered "fpg.cgi" and "sign.tpl" files in a safe place.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 26-08-2010 07:26     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Please note in my previous post that in step one, that code is all one string which belongs all on the same line. Depending on the size of your web browser window, it may possibly word wrap the line so that it appears as multiple lines.

If anyone uses this code, and encounters any problems with it, please note that I did NOT write the code. Highlander found the javascript online, and I simply figured out how to implement it in FPG.

However, I will try to help you if you encounter any problems with installing the code in FPG. It is a basic javascript code, so there really isn't any reason why it should work, unless a person has javascript disabled in their web browser.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 16:43     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
Hi WordWeaver

Thanks for the postings. I tested your form with interest if it would report an error on submitting beyond the character limit and it did which is great and leads me to asking where you added the code which says:

» Your message is too long (xxxx characters)
» Maximum length allowed: 2000 characters

One reason I liked the code is because it correctly handles any copy & paste text and if you delete characters immediately afterwards or cut. Other scripts I tried failed and also this script has the ability to disable copy & paste.

The JavaScript code has two main functions:

* Function taLimit is used for the Key Press event for the text box or text area. When a key is pressed this function checks if the total number of characters typed equals the limit allowed (value maxL defined in the javascript code). If the limit is reached then it return false thus not allowing any further key press event.

* Function taCount is used for the Key Up event. We use this to change the value of the counter displayed and to truncate the excess characters if any (example if someone has cut and pasted the value into the field when we have allowed paste). To disable paste add the property onpaste="return false" to the field. We have used the inner text property of the span element to change the counter displayed.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 26-08-2010 18:52     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Hello Highlander,

Actually, the returned error message is NOT a part of the character count javascript that we installed; it is a part of the guestbook itself.

While the new javascript counts and reports the number of characters used, it is the fact that I have FPG set to a 2000 character limit in the admin section, which is causing the error message to pop up.

The actual contents of those two strings can be edited in FPG's "english.lang" file.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 26-08-2010 19:09     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Thanks for the nopaste parameter. That may come in very useful at some point. For now though, I am leaving it out, being as in the years that I have been using FPG, no spambot has ever gotten past the captcha test.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 19:15     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
quote:
Originally posted by WordWeaver:
Hello Highlander,

Actually, the returned error message is NOT a part of the character count javascript that we installed; it is a part of the guestbook itself.

While the new javascript counts and reports the number of characters used, it is the fact that I have FPG set to a 2000 character limit in the admin section, which is causing the error message to pop up.

The actual contents of those two strings can be edited in FPG's "english.lang" file.


I wasn't thinking straight when asking this as I've already experimented with the character limit. I hope to add the new feature in the next few days.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 20:52     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
ok ive encountered a problem i'm using Firefox on a mac i havent yet tested others.

try signing one of my guestbooks by pasting this:

limited character length (usually needed for forms that submit data to a database) it is always a good idea to tell the user how many characters they have remaining. This javascript snippet is especially useful for textarea fields since they can't be assigned a text limit in HTML but can be restricted using this code.

The following example shows how you can do this. This is a very simple and cute idea to help the user know exactly how many characters can be typed further. Do these small add-ons to your forms and they will look really professional. We recommend using this counter inside CMS solutions and custom built Admin Panels where your clients/visitors can be instructed to use all browsers like IE, Opera, FireFox, Netscape or Safari.

Its fine if you delete before maximum characters but if you type beyond my 750 limit it wont let you delete.

try signing http://www.tenerife.uk.com/cgi-bin/fpg.cgi?

i tried your form and as soon as you go beyond 2000 characters the delete doesnt work

[This message has been edited by Highlander (edited 26-08-2010).]

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 21:26     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
i cant understand i tried the script page example before this http://www.smartwebby.com/DHTML/textbox_characters_counter.asp and it appeared to pass all my testing but now cut & paste tests fail

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 23:28     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
until we find a proper solution ive used this (change 750 to your preferred maximum characters) and also in » Change admin password and configure FPG:
http://www.javascriptkit.com/javatutors/javascriptkey3.shtml

in the fpg.cgi file change:

from this
$input = "<textarea name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";

to this
$input = "<textarea onkeyup=\"return limitlength(this, 750)\" name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";


and in head area of sign.tpl put:

<script type="text/javascript">

function limitlength(obj, length){
var maxlength=length
if (obj.value.length>maxlength)
obj.value=obj.value.substring(0, maxlength)
}

</script>

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 26-08-2010 23:33     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
its one problem after another, i now find my textarea scrolling back to the top when scroll bars are in use so you need to scroll back down to see what your typing. NO USE AT ALL.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 27-08-2010 19:32     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
for the time being i found a script.

1. In the "fpg.cgi" file change (string belongs all on the same line)

From this . . .

$input = "<textarea name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";

To this . . .

$input = "<textarea onkeyup=\"count(this)\" name=\"$hash{'NAME'}\" cols=\"$hash{'COLS'}\" rows=\"$hash{'ROWS'}\" class=\"$hash{'CLASS'}\" $hash{'JAVASCRIPT'}>$hash{'VALUE'}</textarea>";

2. In the "sign.tpl" file, add the following javascript code to the "head" section of the file (change 750 to your preferred character limit):

<script type="text/javascript">
var lim=750;
function count(a){
var dif = lim-a.value.length;
while(dif<0){
a.value=a.value.replace(/.$/,'')
dif = lim-a.value.length;
}
document.getElementById('myspan').firstChild.data=dif;
}
</script>

3. Further down in the same "sign.tpl" file, find this . . .

<td valign="top" bgcolor="#F0F0F0">
$$FPG_CODES$$<!-- Don't remove this line -->
$$FPG_CODES_OPTION$$<!-- Don't remove this line -->
$$FPG_MESSAGE$$<!-- Don't remove this line --><br>
$$FPG_SMILEYS$$<!-- Don't remove this line -->
</td>

And change it to this (change 750 to your preferred character limit) . . .

<td valign="top" bgcolor="#F0F0F0"> $$FPG_CODES$$
<!-- Don't remove this line -->
$$FPG_CODES_OPTION$$
<!-- Don't remove this line -->
$$FPG_MESSAGE$$
<!-- Don't remove this line -->
<br>
$$FPG_SMILEYS$$
<!-- Don't remove this line --> (Click once to apply)<br>
<div>You have <b><span id="myspan">750</span></b> characters left</div>
</td>


My working example http://www.tenerife.uk.com/cgi-bin/fpg.cgi?

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 31-08-2010 15:49     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Hello Again Highlander,

Sorry for the delay in getting back with you, but I've been a bit busy, as well as a little sick.

Anyway, yes, the previous script did have the problem with getting stuck, and not allowing the user to delete characters if they passed the character limit set by the admin.

I just successfully installed the newer script that you provided. Thanks for sharing it with us.

If I knew how to write javascript, there are a few improvements that I would try to make to the script.

1. Have an admin-definable numerical variable which, when reached, would warn the user with a pop-up window that they are approaching the character limit. The admin can set the variable at whatever value they want.

2. If a spammer tries to copy and paste in a long message that surpasses the character limit, have their browser pop up a window with an admin-definable message in it, letting them know that they've been had.

The one drawback is that if a user has their web browser set to not display pop-ups, the above would be rather useless.

The script works fine as it is, and the above are just a few little extras which would make it a bit nicer.

But, as I said, I am not a javascript programmer by a long shot.

[This message has been edited by WordWeaver (edited 31-08-2010).]

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 01-09-2010 14:35     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
I hope your now feeling better. I'm not so keen on pop-up windows i did see a script where the textarea would fade to a pre-defined colour like white to red warning your reaching the maximim characters, maybe some scripters who read this thread can improve on things.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 01-09-2010 18:04     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Actually, I am not too keen on pop-ups either.

Would you be able to relocate that script that had the color change?

I wonder how easy it would be to implement that code in the current script that we are using.

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 01-09-2010 18:43     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
after some time searching i found it http://www.blueshoes.org/en/javascript/limitedtextarea/?bcRun=1&js=0 you would need to study the license it appears to be ok for your own website if you own at least 20% of it http://www.blueshoes.org/en/get/ and to see the source code you must apply see note 2 on the latter link

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 01-09-2010 23:43     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
I tried to download the full package from their site -- I own my own server and site, not just 20% -- but I kept getting two errors displayed on their download page after hitting the download link.

Well, I realized that I can't use it anyway, because I have never been able to get PHP scripts to work properly on my server. I believe that it uses some kind of proprietary version of PHP, but my server software is old, has been discontinued, and is no longer supported, so I have no way of finding out why PHP scripts won't work.

Oh well. At least we have a script that is working.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 02-09-2010 02:47     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Here is a script that you might find interesting. Instead of using a numerical character counter, it uses a configurable progress bar which shows the percentage of characters used.

Once you reach 100% of the characters allowed, it will zap any additional characters that you try to type into the field.

I haven't tried this in FPG yet,but it definitely works if you place each section of code in the head and body sections of any old HTML file.

This all goes in the head section
=================================


<style type="text/css">

.progress{
width: 1px;
height: 14px;
color: white;
font-size: 12px;
overflow: hidden;
background-color: navy;
padding-left: 5px;
}
</style>
<script type="text/JavaScript">


/***********************************************
* Form Field Progress Bar- By Ron Jonk- http://www.euronet.nl/~jonkr/
* Modified by Dynamic Drive for minor changes
* Script featured/ available at Dynamic Drive- http://www.dynamicdrive.com
* Please keep this notice intact
***********************************************/

function textCounter(field,counter,maxlimit,linecounter) {
// text width//
var fieldWidth = p****Int(field.offsetWidth);
var charcnt = field.value.length;

// trim the extra text
if (charcnt > maxlimit) {
field.value = field.value.substring(0, maxlimit);
}

else {
// progress bar percentage
var percentage = p****Int(100 - (( maxlimit - charcnt) * 100)/maxlimit) ;
document.getElementById(counter).style.width = p****Int((fieldWidth*percentage)/100)+"px";
document.getElementById(counter).innerHTML="Limit: "+percentage+"%"
// color correction on style from CCFFF -> CC0000
setcolor(document.getElementById(counter),percentage,"background-color");
}
}

function setcolor(obj,percentage,prop){
obj.style[prop] = "rgb(80%,"+(100-percentage)+"%,"+(100-percentage)+"%)";
}
</script>


This all goes into the body section
===================================


<form>
<textarea rows="10" cols="60" name="maxcharfield" id="maxcharfield" onkeydown="textCounter(this,'progressbar1',200)" onkeyup="textCounter(this,'progressbar1',200)" onfocus="textCounter(this,'progressbar1',200)">
</textarea><br>
<div id="progressbar1" class="progress"></div><script type="text/javascript">
textCounter(document.getElementById("maxcharfield"),"progressbar1",200)
</script>
</form>


And to add a background image to your textarea, you can also add this CCS style code to your head section as well:


<style type="text/css">
textarea{
background-image:url(http://www.yourdomain.com/yourimagepath.gif);
color:ff0000;
}
</style>


---

[This message has been edited by WordWeaver (edited 02-09-2010).]

IP: Logged

Highlander
Junior Member

Posts: 23
From: Scotland
Registered: Oct 2008

posted 04-09-2010 19:20     Click Here to See the Profile for Highlander     Edit/Delete Message   Reply w/Quote
The link doesnt appear to be valid but in any case you've shown the code, i think this is the script http://www.dynamicdrive.com/dynamicindex16/limitinput2.htm

I didn't realize it was PHP sorry about that.

To take things further it would be great to also limit the number of rows and display ie.

You have xxx characters and xx lines remaining

I'm searching for something suitable which is easy to add to our existing set-up.

IP: Logged

WordWeaver
Member

Posts: 41
From: Guam
Registered: Dec 2005

posted 06-09-2010 12:03     Click Here to See the Profile for WordWeaver     Edit/Delete Message   Reply w/Quote
Actually, since posting the above script, I have found another one which I am now using on our site's "contact us" page. It has both a decreasing character count, as well as a progress bar. Once the person uses up all of their allotted characters, the progress bar changes from one color to another...which is admin-configurable. I haven't tried using it with FPG yet, but I don't see why it wouldn't work.

IP: Logged

All times are GMT + 1

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic

Post New Topic  Post A Reply

E-Mail | Home

Powered by Infopop www.infopop.com © 2000
Ultimate Bulletin Board Freeware Version 2000C