1. Go to this page and download the library: Download c975l/contactform-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
c975l / contactform-bundle example snippets
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use c975L\ContactFormBundle\Event\ContactFormEvent;
class ContactFormSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
ContactFormEvent::SEND_FORM => 'onSendForm',
];
}
public function onSendForm(ContactFormEvent $event): void
{
$subject = $event->getFormData()->getSubject();
if (str_contains((string) $subject, 'some-keyword')) {
$event->setEmailData([
'subject' => 'Custom email subject',
'bodyEmail' => 'emails/custom_contact.html.twig',
'bodyData' => [],
]);
// Or abort sending with an error code:
// $event->setError('error.user_not_found');
}
}
}
public function onCreateForm(ContactFormEvent $event): void
{
$event->getRequest()->getSession()->set('redirectUrl', 'https://example.com/thank-you');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.