Contact Form using maxlength

Permalink
I need to set a maxlength of 2 on an input field for a contact form block. Does anyone have a solution for this? There doesn't seem to be an option for this using the basic form block.

Thanks!

joemc
 
jordanlev replied on at Permalink Reply
jordanlev
The built-in form block is very limited. If you have a budget for your project, I'd recommend the "Extended Form" from the marketplace -- it costs a little bit of money but is worth it.

If you want to go your own way (which requires some php coding), try the free "Form Tableless Layout" addon and grab the field name in the loop of the template and if it matches the field you want, insert the maxlength attribute. Actually, that might be really hard to do now that I think about it -- maybe just putting some javascript/jquery on the page to grab that form field in question and setting its maxlength attribute to 2 might be better -- something like this:
$(document).ready(function() {
  $('input[name="surveyQuestion123"]').attr('maxlength', 2);
});

you'll need to add the form to the page first and find out what its "name" is though. Super hacky -- honestly you're probably best off with the Extended Form block.
joemc replied on at Permalink Reply
joemc
Thanks, Jordan. I ended up making a custom template and just manually inserting an input field (with the same id/name as the auto-created one) with a maxlength... not the most flexible solution, but for this job it won't matter.

If there where more issues than just that I would have probably purchased the Extended Form Block (I have used this on another site).

Thanks again for the tips.