Re: Cannot read property 'length' of undefined - forms 2.0

Anonymous
Not applicable

Cannot read property 'length' of undefined - forms 2.0

On our WordPress site, we intermittently get this error that causes the forms to be unable to submit.

Uncaught TypeError: Cannot read property 'length' of undefined. forms2.min.js

The error is here (formatted js):

each: function(a, b, c) {     var e, f = 0, g = a.length, h = d(a);    if (c) {         if (h)             for (; g > f && (e = b.apply(a[f], c),             e !== !1); f++)                 ;         else             for (f in a)                 if (e = b.apply(a[f], c),                 e === !1)                     break     } else if (h)         for (; g > f && (e = b.call(a[f], f, a[f]),         e !== !1); f++)             ;     else         for (f in a)             if (e = b.call(a[f], f, a[f]),             e === !1)                 break;     return a },

I built it to use the REST API in order to prepopulate the form fields on each page with lead data. Most of the time, it works. However, sometimes I get reports of the forms not submitting. After a few hard refreshes and/or 10 min, the error stops occurring and everything is back to normal.

Thanks in advance for any help.

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Cannot read property 'length' of undefined - forms 2.0

Since you're not providing your in-house code nor an example URL, it's not possible to tell you what's wrong.

I assume the problem is caused by your code altering the form DOM in a way that makes the Forms2 lib barf.  It's easy to make this happen if you're not careful, but it's not Marketo's fault. I have a feeling you're not using the Forms API to set field values: this often goes wrong.

As for the REST-based prefill -- I can't endorse that. It's an instant DoS vulnerability, as I have mentioned numerous times here.