A newer version of

Freeform

is available.

Try Freeform 5 now →

Freeform Freeform for Craft

Developer Events

Miscellaneous Events

Adding Attributes to Injected JS and CSS Scripts

You can use this event if you need to attach any attributes to the <script> and <style> tags which are added by Freeform.

use Solspace\Freeform\Events\Forms\RegisterRenderObjectOptionsEvent;
use Solspace\Freeform\Library\DataObjects\FormRenderObject\AbstractFormRenderObject;
use yii\base\Event;

Event::on(
    AbstractFormRenderObject::class,
    AbstractFormRenderObject::EVENT_REGISTER_OPTIONS,
    function (RegisterRenderObjectOptionsEvent $event) {
        $nonce = 'abc'; // Get your nonce here
        $event->addOption('nonce', $nonce);
    }
);
1
2
3
4
5
6
7
8
9
10
11
12

Altering the Honeypot Markup

If you need to change something on the honeypot markup which is added by Freeform, use this event.

use Solspace\Freeform\Services\HoneypotService;
use Solspace\Freeform\Events\Honeypot\RenderHoneypotEvent;

Event::on(
    HoneypotService::class,
    HoneypotService::EVENT_RENDER_HONEYPOT,
    function (RenderHoneypotEvent $event) {
        $output = $event->getOutput();

        $output = str_replace(
            ' class="',
            ' nonce="my-nonce" class="',
            $output
        );

        $event->setOutput($output);
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18