[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>
&lt;dtml-var &quot;my_string[:10]&quot;&gt;<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>
&lt;dtml-call &quot;REQUEST.set('my_string', 'this is way too long, man')&quot;&gt;<br>
&lt;dtml-call &quot;REQUEST.set('max_length', 6)&quot;&gt;<br>
&lt;dtml-var &quot;my_string[:max_length]&quot;&gt;<br><br>
will show up as &quot;this i&quot;<br><br>
Hope this helps,<br>
Danny</html>