The code runs, the portal id and form id are using correct values, v2-legacy.js and v2.js are both loaded. However the form is not displayed anywhere on the page and I receive the following error in the developer console.
ERROR TypeError: "hbspt.forms.create is not a function"
That was my initial thought which is why the call to hbspt.forms.create is in the onload of the v2.js which isn't added until the onload of the v2-legacy.js. Even added a 10second timeout after v2.js loads before calling hbspt.forms.create just to be safe. Didn't change anything unfortunately.
Does the form load on the page when you use static values in the embed code? Like if you have just copied it right from the hubspot form creator? The only thing I can think of is that maybe your v2-legacy.js and v2.js are being loaded after your form creation and not being seen?