User Tools

Site Tools


tutorials:zencartmods:comments_max_length.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:zencartmods:comments_max_length.html [2011/08/24 17:50]
ladyada
tutorials:zencartmods:comments_max_length.html [2016/01/28 18:05]
Line 1: Line 1:
  
-====== Text box length limits ====== 
- 
-{{:​tutorials:​zencartmods:​limitcomment.png?​|}} 
- 
-Here's a quick way to limit the length of customer comments on your invoices using javascript. Essentially,​ this is just a script to limit the size of a **<​textarea>​** element. This can be handy when you want to keep comment fields short 
- 
- 
-in both **includes/​templates/​YOUR_TEMPLATE/​templates/​tpl_checkout_shipping_default.php** and **includes/​templates/​YOUR_TEMPLATE/​templates/​tpl_checkout_payment_default.php** 
- 
-find this line (might be different depending on your template) 
-<code php> 
-<?php echo zen_draw_textarea_field('​comments',​ '​45',​ '​3'​);​ ?> 
-</​code>​ 
- 
-and insert BENEATH it 
- 
-<code php> 
-Max 140 Characters (<div style="​display:​inline"​ id="​charCount">​140</​div>​ remain) 
-<​script>​ 
-comments = document.getElementsByName("​comments"​)[0];​ 
- 
-// Cover all your bases just to be sure 
-comments.onkeydown = commentstuff;​ 
-comments.onkeypress = commentstuff;​ 
-comments.onkeyup = commentstuff;​ 
-comments.onblur = commentstuff;​ 
-comments.onfocus = commentstuff;​ 
-comments.onclick = commentstuff;​ 
-comments.onselect = commentstuff;​ 
-function commentstuff(){ 
-if (comments.value.length > 140) 
-    { 
-      comments.value = comments.value.substring(0,​ 140); 
-    } 
-  remain = 140 - comments.value.length;​ 
-  document.getElementById('​charCount'​).innerHTML = remain; 
-} 
-  remain = 140 - comments.value.length;​ 
-  document.getElementById('​charCount'​).innerHTML = remain; 
-</​script>​ 
- 
-</​code>​ 
- 
- 
-And you're done! Of course, this is pretty easy to hack (you could just turn off javascript in your browser). If you really need to limit this field legitimately you should probably do it server-side in the php.  
- 
- 
- 
-  
/home/ladyada/public_html/wiki/data/pages/tutorials/zencartmods/comments_max_length.html.txt · Last modified: 2016/01/28 18:05 (external edit)