SOLVED

Marketo web form character limit

Go to solution
Joshenser
Level 2

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! 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo web form character limit

 

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

 

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo web form character limit

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

Joshenser
Level 2

Re: Marketo web form character limit

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
Level 10 - Community Moderator

Re: Marketo web form character limit

 

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