I've added a new feature to form builder elements: "maxlength".
Use like this:
element create myform term_name -label "Term name" -datatype text -maxlength 20
What it'll do is add a maxlength="20" attribute to the input widget.
But moreover, it'll also validate the value on the server side, with a call to [string bytelength], which correctly handles multibyte characters.
The error message to the user will be "Term name is 3 characters too long". The reason we don't explicitly say what the maxlength is, is that it depends on the presence of multibyte characters. So telling him to remove 3 will always work. If he removes multibyte characters, he could get away with removing fewer, but if he removes 3, he's guaranteed to be safe.
I've also added it to ad_form:
{term_name:text {label "Term name"} {maxlength 20}}
Please use liberally on all your forms, so we can avoid those nasty DB errors causing 500 internal server errors, just because the user typed a few characters too much.
/Lars