# Help - Broken Form - Code issue

**URL:** <https://community.hubspot.com/t/help-broken-form-code-issue/105472>\
**Category:** CMS Development\
**Tags:** css, html, professional\
**Created:** [April 22, 2024, 8:20pm UTC](https://community.hubspot.com/t/help-broken-form-code-issue/105472 "2024-04-22T20:20:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JRivera-Salva](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@JRivera-Salva](https://community.hubspot.com/u/JRivera-Salva)\
**Post date:** [April 22, 2024, 8:20pm UTC](https://community.hubspot.com/t/help-broken-form-code-issue/105472/1 "2024-04-22T20:20:55Z")

</div>

Hello Fellow HubSpoters I have a page [Online MBA Programs](https://info.online.saintleo.edu/online-mba) that has a custom coded form from hubspot that was made into a multi-step form with some custom code. It was working for a number of years and now it seems to have stopped loading correctly. I have tried looking at the code and making changes but I have hit a road block. The issue is the form loads without the multi-step and is affecting load times. And help would be appreciated. You can tell it hasn’t loaded correctly when the backgoruand image is of just 1 student instead of two.

---

<div class="post-metadata">

**Author:** ![Gracjan](https://avatars.discourse-cdn.com/v4/letter/g/e99b99/32.png) [@Gracjan](https://community.hubspot.com/u/Gracjan)\
**Post date:** [April 22, 2024, 8:57pm UTC](https://community.hubspot.com/t/help-broken-form-code-issue/105472/2 "2024-04-22T20:57:31Z")

</div>

Hello @JRivera-Salva

I’ve noticed that the form sometimes loads correctly and sometimes not. How do you load the custom code for creating the steps? I suspect the problem is that HubSpot Forms are being loaded with JavaScript, and sometimes the form isn’t fully loaded on your page when your custom function runs.

To address this, ensure that the form is fully loaded on your page before running your custom code to create the steps.

You can achieve this using the HubSpot form custom events: [HubSpot Global Form Events](https://legacydocs.hubspot.com/global-form-events).  
In your case you need the onFormReady event. You should wrap your custom code with this If statement:

```lia-code-sample
window.addEventListener('message', event => {
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady) {
 // YOUR CUSTOM CODE FOR CREATING STEPS
 }
});

```

You could also implement some kind of placeholder or loading spinner to avoid massive page shifting while loading and creating the multistep form.  
Hope this helps.  
Regards,  
Gracjan
