Skip to content

Latest commit

 

History

History
32 lines (23 loc) · 969 Bytes

023_Using_events.md

File metadata and controls

32 lines (23 loc) · 969 Bytes

Using Events

The Bundle provides two events - PreSendMailEvent where you can handle the raw form request and PostSendMailEvent where you can do something with the parsed data. Here is a example usage:

Create src/EventListener/ContactFormListener.php in your Pimcore installation with following content:

<?php

namespace App\EventListener;

use SimpleFormsBundle\Event\PostSendMailEvent;
use Pimcore\Log\Simple as Log;

class ContactFormListener
{
    public function onFormSend(PostSendMailEvent $event)
    {
        Log::log('contact-form', $event->getData()['email']);
    }
}

We assume that the form has a field email. This listener will write the sender address in a log file for each sender. To register the listener add

    App\EventListener\ContactFormListener:
        tags:
            - { name: kernel.event_listener, event: simple_forms.post_send_mail, method: onFormSend }

to your config/services.yaml. Thats it.