|
THE DISCUSSION BOARD OF VITINH.DE
![]() Free Perl Guestbook - F.A.Q
![]() Message Character Limit
|
| next newest topic | next oldest topic |
| Author | Topic: Message Character Limit |
|
Highlander Junior Member Posts: 23 |
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 |
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 |
This solution appears to be ideal: http://www.smartwebby.com/DHTML/textbox_characters_counter.asp IP: Logged |
|
WordWeaver Member Posts: 41 |
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 |
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 |
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 |
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 |
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 |
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 |
HOW TO USE THE CHARACTER COUNTER CODE WITH FPG
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>";
<script language="Javascript" type="text/javascript"> maxL=2000; function taCount(taObj,Cnt) { 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.
<td valign="top" bgcolor="#F0F0F0"> And change it to this . . . <td valign="top" bgcolor="#F0F0F0"> 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.
IP: Logged |
|
WordWeaver Member Posts: 41 |
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 |
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) 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 |
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 |
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 |
quote: 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 |
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 |
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 |
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 to this
<script type="text/javascript"> function limitlength(obj, length){ </script> IP: Logged |
|
Highlander Junior Member Posts: 23 |
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 |
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"> 3. Further down in the same "sign.tpl" file, find this . . . <td valign="top" bgcolor="#F0F0F0"> And change it to this (change 750 to your preferred character limit) . . . <td valign="top" bgcolor="#F0F0F0"> $$FPG_CODES$$
IP: Logged |
|
WordWeaver Member Posts: 41 |
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 |
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 |
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 |
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 |
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 |
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
.progress{
function textCounter(field,counter,maxlimit,linecounter) { // trim the extra text else { function setcolor(obj,percentage,prop){
[This message has been edited by WordWeaver (edited 02-09-2010).] IP: Logged |
|
Highlander Junior Member Posts: 23 |
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 |
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 |
![]() |
|
Powered by Infopop www.infopop.com © 2000
Ultimate Bulletin Board Freeware Version 2000C