APIs & Integrations

naveen
Member

Max character length for input field in hubspot form

Hi I have created a form in hubspot and embedded it on the website and I want to set max character length for one of the input field can you tell me is there any option for this or is there other way to do it.

4 Replies 4
Not applicable

Max character length for input field in hubspot form

hbspt.forms.create({
css: ‘’,
portalId: ‘######’,
formId: ‘########-####-####-####-########’,
onFormReady: function($form) {
$(“input[name=field-name]”).attr(‘maxlength’,‘16’);
$(“input[name=field-name]”).attr(‘maxlength’,‘4’);
$(“input[name=field-name]”).attr(‘maxlength’,‘10’);
$(“input[name=field-name]”).attr(‘maxlength’,‘2’);
}
});

0 Upvotes
Jobby_Cheong
Member

Max character length for input field in hubspot form

Hi, I try to use the sample above by using the onFormReady function and put back in the website. It does not work, the form does not display in the website. I am wondering if I miss out anything?
Example:

hbspt.forms.create({
portalId: "#######",
formId: "########-####-####-####-##########",
onFormReady: function($form) {
$(“input[name=message]”).attr(‘maxlength’,‘255’);
});

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

Max character length for input field in hubspot form

Hi @naveen

This type of validation isn’t something that our forms currently support natively. If you’re using the embed code to include the forms on your site, it would be possible to use the onFormReady function in the embed code to add that functionality to the field, but you’d need to write the JavaScript to do that.

0 Upvotes
naveen
Member

Max character length for input field in hubspot form

Hi Dadams

Thanks for reply but I have many forms and I want to set the max length for “job title input field”. I have checked the id attribute of input field it’s “jobtitle-formid” so can you tell me the generic way to add max length.

0 Upvotes