Marketo web form character limit | Community
Skip to main content
Level 2
February 8, 2022
Solved

Marketo web form character limit

  • February 8, 2022
  • 1 reply
  • 2293 views

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! 

Best answer by SanfordWhiteman

 

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

 

 

1 reply

SanfordWhiteman
Level 10
February 8, 2022

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

JoshenserAuthor
Level 2
February 8, 2022

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)

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
February 8, 2022

 

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