An easy way to set max character input on Marketing Cloud Account Engagement Forms
I haven't spent much time in Marketing Cloud Account Engagement (MCAE) lately, but this week I was asked to help handle character limits in Salesforce fields. The field size is not reflected in MCAE form fields, and therefore leads to errors when the input that exceeds the Salesforce limit is inserted into a Salesforce field.
I was a little shocked to find out that MCAE does not have this functionality in place already.
There are a couple of lengthy code-based solutions here and here.
<script> const target = document.querySelector(".zip input"); target.setAttribute('maxlength',5); </script>
You can repeat these two lines for each field you want to target, if you need to target more than one. The ".zip" in the querySelector refers to a class in the <div> that encompasses the input.
The below screenshot shows you how easy it is to target the field you want. MCAE uses the name of the field as a class. The zip field has a "zip" class. The state field has a "state" class. Et cetera. If you want to apply the maxlength to multiple fields, you can add a class in to CSS Classes in each field's Advanced Options.
For future built-in functionality, there is an idea that can be upvoted.