[Zope] Trimming a text field in a form
Danny William Adair
danny@adair.net
Wed, 19 Sep 2001 02:11:38 -0400
<html>
Hi Tommy!<br><br>
<blockquote type=cite class=cite cite>Another question. How do you trim a form field with dtml? I have JavaScript<br>
doing it when the form is submitted, but that doesn't help much for those<br>
browsers whose user's have disabled JavaScript.</blockquote><br>
A string is a sequence type, so you can do a simple<br><br>
<dtml-var "my_string[:10]"><br><br>
to trim your field input (first 10 characters, in this case). Of course you can use a variable holding the length, instead of the integer literal 10...<br><br>
<dtml-call "REQUEST.set('my_string', 'this is way too long, man')"><br>
<dtml-call "REQUEST.set('max_length', 6)"><br>
<dtml-var "my_string[:max_length]"><br><br>
will show up as "this i"<br><br>
Hope this helps,<br>
Danny</html>