Embedded form open in parent window from lightbox

Hi everyone,

I’m having trouble with an embedded form not opening the redirect page in a new or parent window. It’s embedded in a different platform than hubspot.

Here is the page - the form is in a lightbox. When you submit it opens in the new window - but it does not redirect to the submit page. The redirect url is set in hubspot - I have tried adding it to the embed script as well though and it does the same thing.

https://m.gameplanmarketing.ca/form-test/

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
 hbspt.forms.create({
	region: "na1",
	portalId: "203948",
	formId: "73a77784-c371-449c-a687-02231ad83c15",
 onFormReady: function (form) {
		form.attr('target', '_blank');
	}
});
</script>

Any help would be appreciated.

Thanks

Hi @dsheets74 ,

I see that the redirectUrl is set correctly to 10 Effective Strategies for Networking Remotely with IT Pros

You can check the settings of the form in the hidden input hs_context:

{
 "rumScriptExecuteTime":597.5,
 "rumServiceResponseTime":844.1999999992549,
 "rumFormRenderTime":2.7000000029802322,
 "rumTotalRenderTime":91.20000000298023,
 "rumTotalRequestTime":244.59999999776483,
 "lang":"en",
 "embedType":"REGULAR",
 "embedAtTimestamp":"1631535187582",
 "formDefinitionUpdatedAt":"1631532015536",
 "pageUrl":"https://m.gameplanmarketing.ca/form-test/a-10-lightbox.html",
 "source":"FormsNext-static-5.365",
 "timestamp":1631535187586,
 "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36",
 "referrer":"https://m.gameplanmarketing.ca/form-test/",
 "originalEmbedContext":{
 "region":"na1",
 "portalId":"203948",
 "formId":"73a77784-c371-449c-a687-02231ad83c15",
 "target":"#hbspt-form-1631535187765-6867067663",
 "shellId":0,
 "shell":true,
 "pageUrl":"https://m.gameplanmarketing.ca/form-test/a-10-lightbox.html",
 "referrer":"https://m.gameplanmarketing.ca/form-test/"
 },
 "redirectUrl":"https://info.gameplanmarketing.ca/10-tips-for-remote-networking-with-it-pros",
 "formValidity":{
 "firstname":{
 "valid":true
 }
 },
 "domFields":[
 "firstname"
 ],
 "formTarget":"#hbspt-form-1631535187765-6867067663",
 "correlationId":"eb6aed55-ffa8-4d1e-bec6-855adb8a9caf",
 "hutk":"469d5d68a7370944fa029f9c9ca1b33d",
 "useRecaptchaEnterprise":true,
 "isIframe":true
}

It seems as if this line is messing with the functionality:

form.attr('target', '_blank');

Could you try to remove it just to see if it works without this function?

Yes it does work without the form.attr line - it will open the redirect page in the lightbox.

I will try rewriting the function.

@dsheets74 If that works, you can rewrite your function to do something like this (instead of target _blank):

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
 hbspt.forms.create({
	region: "na1",
	portalId: "203948",
	formId: "73a77784-c371-449c-a687-02231ad83c15",
 onFormSubmitted: function ($form) {
 window.open(
 'https://info.gameplanmarketing.ca/10-tips-for-remote-networking-with-it-pros',
 '_blank'
 );
	}
 });
</script>

If you want to use the redirectUrl set through the form instead of hardcoding the redirect URL, try logging $form to see if it contains the redirectUrl. Otherwise you need the values of the hs_context input, decode that and retrieve the redirectUrl that way.