How to actually set a maxlength for textarea field in contact form I need to limit the textarea message of the core module contact form to a certain number of characters.

Here are the facts


The Form API does not allow one to set a maxlength on textarea field types [while plain HTML does]
The Maxlength module , doesn't allow you to actually set a maximum length. It gets its max length from the field's max length, defined on each content type's manage field section
Creating a new form element type using hook_element_info, still doesn't gurantee I can add the #maxlength to the textarea. Besides if I succeed I need to alter again the contact form module to overrride actual message textarea field with mine.


So I can I alter it plain and straightforward?

What is the best idea to alter all textarea fields in the website?
The Form API does not allow to set a maxlength on textarea field types [while plain HTML does]


That's not strictly true....HTML5 introduced a maxlength property for textareas, previous versions do not have it (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea). 

The default templates that come with Drupal 7 all use XHTML, so the lack of explicit support for HTML5 makes perfect sense.

As long as your doctype is HTML5, this will probably work:

$form['element'] = array(
  '#type' =&gt; 'textarea',
  '#attributes' =&gt; array('maxlength' =&gt; 200),
);