Re: HTML_QuickForm - can you impose maxlength on a textarea?

From: Date: Fri, 12 Nov 2004 18:49:57 +0000
Subject: Re: HTML_QuickForm - can you impose maxlength on a textarea?
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15477@lists.php.net to get a copy of this message
On Fri, 12 Nov 2004 15:33:52 +0100, I. M. Bur <buralien@gmail.com> wrote: > > Thanks. Please allow me to ask a follow up question. In your > > example: > > > > $form->addElement ( 'textarea', 'foo', Bar' ); > > $form->addRule ('foo', 'Error!', 'maxlength', > > '', 'client' ); > > > > How does it know how long the maxlength can be? Where do I put 300 - > > no more than 300 characters? > > > > That's what the fourth parameter of the addRule() method is for. > Sorry, my bad, should have mentioned it the first time... > > $form->addRule ('foo', 'Error!', 'maxlength', 300, > 'client' ); > > This will limit the field to 300 characters. But beware, it will not > limit the number of characters, that can be entered into the field, > just the number of characters that can be submited. So the user can > paste a 1000 character long essay, but he will get a javascript > warning when trying to submit the form, unlike the fixed 'maxlength' > on a <text> tag. > You could add JS which checks as the user is typing and stops them from entering too much. It would be about as effective as the maxlength attribute. Both can be overridden, though, so server-side validation should always be done. -- Justin Patrin

« previous php.pear.general (#15477) next »