Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Set Gift Message Limit to 300 Characters. 
 
AnshumaanBakshi
Member
 
Avatar
Total Posts:  33
Joined:  2008-11-14
Delhi, India
 

I recently had an requirement to limit the gift message to 300 characters. As the gift message is filled in a text area hence we need to use a small JavaScript code in order to implement this limit.

Please find an attached file named inline.phtml which needed to be placed at

magento\app\design\frontend\default\default\template\giftmessage\inline.phtml

All the code required is inside this file.

This file will display a message to the user if he exceeds 300 characters limit and even reduce the charters entered by him to below 300.

I made changed in this script for Magento version 1.1.8

Any questions then let me know

Thanx
Anshumaan Bakshi

File Attachments
inline.phtml  (File Size: 18KB - Downloads: 164)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Mike
Member
 
Total Posts:  43
Joined:  2007-09-11
Los Angeles, CA
 

For anyone interested in using this character limit notification in more recent versions of Magento, it\’s a simple matter of adding a copy of inline.phtml to your theme\’s directory and then editing it as noted below.

Copy from inline.phtml from magento\\app\\design\\frontend\\base\\default\\template\\giftmessage\\inline.phtml to
magento\\app\\design\\frontend\\default\\YOURTHEME\\template\\giftmessage\\inline.phtml.

Then, with that copied version of inline.phtml, edit the code (around line 60 in v1.4.1.1) that reads:

if(!$(source).value.blank()) {
            objects
.each(function(item{

to read

if(!$(source).value.blank())
        
{            
            
if($(source).value.length 300)
            
{
                alert(\
'Please limit your message to 300 characters\');
                $(
source).value=$(source).value.substring(0,300);
            
}
            
            objects
.each(function(item{

NOTE: Pay special attention to instances of “{” as the code in the original file has a “{” at the end of the first line and, if it’s left in, it will cause things to not work as expected.

This is the same code used in AnshumaanBakshi\’s code above, except that I\’ve corrected the spelling of \"characters\" in the alert message.

If you want to use a number of characters other than 300, simply edit the 3 instances of \’300\’ in the code above to represent the number you wish to use.

A nice side feature of this code is that it notifies the customer to limit the message to 300 characters, then automatically truncates the existing message down to 300 characters. Naturally, it would be great to have a more robust system (that counts down how many characters are left/available within a message field); but this is a good simple fix when character limits are needed on gift message fields.

Enjoy!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top