Re: HTML_QuickForm - can you impose maxlength on a textarea?
| From: | I. M. Bur | Date: | Fri, 12 Nov 2004 14:33:52 +0000 |
| Subject: | Re: HTML_QuickForm - can you impose maxlength on a textarea? | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15470@lists.php.net to get a copy of this message | ||
> 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.
--
I. M. Bur
buralien@gmail.com