Re: HTML_QuickForm - can you impose maxlength on a textarea?
| From: | I. M. Bur | Date: | Fri, 12 Nov 2004 14:12:53 +0000 |
| Subject: | Re: HTML_QuickForm - can you impose maxlength on a textarea? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15468@lists.php.net to get a copy of this message | ||
> I'd like to impose a maximum # of characters on a textarea. Here are
> the two things I have tried without success:
>
> $attrs = array("rows"=>"5", "cols"=>"40",
> "maxlength"=>"30");
> $form->addElement('textarea', 'field1', 'Enter Data: ',
> $attrs);
>
> AND
>
> $form->addElement('textarea', 'field1', 'Enter Data: ',
> array('rows'=>'5', 'cols'=>'40',
> 'maxlength'=>'30'));
>
> Any other ideas are much appreciated!
There is no such attribute as maxlength on the <textarea> tag:
http://www.w3.org/TR/html401/interact/forms.html#edef-TEXTAREA
You can use define a validation rule on the element, as explained here:
http://pear.php.net/manual/en/package.html.html-quickform.intro-validation.php
Like this:
<?php
$form->addElement ( 'textarea', 'foo', Bar' );
$form->addRule ('foo', 'Error!', 'maxlength', '',
'client' );
?>
--
I. M. Bur
buralien@gmail.com