-
Notifications
You must be signed in to change notification settings - Fork 60
/
Cookies.php
44 lines (36 loc) · 1.03 KB
/
Cookies.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Solspace\Freeform\Bundles\Form\Tracking;
use Solspace\Freeform\Events\Forms\SubmitEvent;
use Solspace\Freeform\Library\Bundles\FeatureBundle;
use Solspace\Freeform\Library\Composer\Components\Form;
use yii\base\Event;
class Cookies extends FeatureBundle
{
public function __construct()
{
Event::on(Form::class, Form::EVENT_AFTER_SUBMIT, [$this, 'setPostedCookie']);
}
public static function getCookieName(Form $form): string
{
return 'form_posted_'.$form->getId();
}
public function setPostedCookie(SubmitEvent $event)
{
if (\Craft::$app->request->isConsoleRequest) {
return;
}
$form = $event->getForm();
$name = self::getCookieName($form);
$value = time();
setcookie(
$name,
$value,
(int) strtotime('+1 year'),
'/',
\Craft::$app->getConfig()->getGeneral()->defaultCookieDomain,
true,
true
);
$_COOKIE[$name] = $value;
}
}