I have a Hubspot (service outside my server) form that appears after a certain amount of pages is viewed and want to set a cookie after that form is submitted. I've tested the code with an HTML form and it worked fine, but with the Javscript created form the PHP isn't seeing that it was submitted.
Hubspot Form
<div id="access" class="modalWindow">
<div>
<h1>To access the rest of this eBook, please fill out the following form.</h1>
<script charset="utf-8" src="//js.hsforms.net/forms/current.js"></script>
<script>
hbspt.forms.create({
portalId: '268874',
formId: '2f79f36a-5c90-47e3-bd54-9d5f0fc674d1'
});
</script>
</div>
</div>
PHP if Statement
<?php
if (!empty($_POST)) {
$value = "Ebook";
setcookie("ebookAccess", $value, time()+3600*24*360, "/ebooks/", "mytestserver.com");
header("Refresh:0");
}?>