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!
Solved! Go to Solution.
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
Are you talking about a single field, or the entire form?
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)
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