Skip to main content
Level 2
Feb 8, 2022 3:58 PM UTC
Solved

Marketo web form character limit

Is there a way to set a limit on a form so that the user is prompted that they have written too much?

 

We recently had a user complete a form with roughly 4k characters inc spaces. Whilst the form was found on the backend of Marketo, we weren't sent an email notification.

 

We need to be able to restrict the character count as ideally, we don't want them submitting lots of information. 

 

Thanks! 

SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Feb 8, 2022 6:12 PM UTC

 

MktoForms2.whenReady(function (mktoForm) {
   let formEl = mktoForm.getFormElem()[0],
       messageEl = formEl.querySelector("[name='message']");

   let maxLength = messageEl.getAttribute("maxlength");

   messageEl.addEventListener("input", function (e) {
      let currentLength = this.value.length;
      // do whatever you want with `currentLength` and `maxLength`
   });
});

(Replace  message with the exact name of your form field.)

 

Example:

MktoForms2 :: Textarea counter

 

 

3 replies

SanfordWhiteman
User Group Leader
User Group Leader
Feb 8, 2022 5:00 PM UTC

Are you talking about a single field, or the entire form?

Translate
JoshenserAuthor
Level 2
Feb 8, 2022 5:11 PM UTC

A single field.

 

We have a simple form first name, last name, email, phone and message.

 

It is the message section of the form which we need to limit, but prompt the user with a character counter (i.e. 43/1000 characters)

Translate
SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Feb 8, 2022 6:12 PM UTC

 

MktoForms2.whenReady(function (mktoForm) {
   let formEl = mktoForm.getFormElem()[0],
       messageEl = formEl.querySelector("[name='message']");

   let maxLength = messageEl.getAttribute("maxlength");

   messageEl.addEventListener("input", function (e) {
      let currentLength = this.value.length;
      // do whatever you want with `currentLength` and `maxLength`
   });
});

(Replace  message with the exact name of your form field.)

 

Example:

MktoForms2 :: Textarea counter

 

 

Translate