Download the PHP package c975l/contactform-bundle without Composer
On this page you can find all versions of the php package c975l/contactform-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download c975l/contactform-bundle
More information about c975l/contactform-bundle
Files in c975l/contactform-bundle
Package contactform-bundle
Short Description Bundle to manage simple contact form
License MIT
Homepage https://github.com/975L/ContactFormBundle
Informations about the package contactform-bundle
ContactFormBundle
ContactFormBundle does the following:
- Display a form to contact a website,
- Pre-fills data if user is logged in,
- Dispatch events to modify form/email,
- Sends the email via c975LEmailBundle as
c975LEmailBundle
provides the possibility to save emails in a database, there is an option to NOT do so via this Bundle, - Sends a copy to the email provided,
- Allows the possibility to send email to other user, related to your app specification, i.e. contact another user without giving its email. This is achieved via event dispatch (see below),
- Provides honeypot and delay before real submission, to avoid spam and not need to request captcha (see below),
ContactFormBundle dedicated web page.
ContactFormBundle API documentation.
Bundle installation
Step 1: Download the Bundle
v5.x works with Symfony 6.x. Use v3|4.x for Symfony 4.x Use v2.x for Symfony 3.x Use Composer to install the library
Step 2: Configure the Bundle
Check dependencies for their configuration:
c975LContactFormBundle uses c975L/ConfigBundle to manage configuration parameters. Use the Route "/contact/config" with the proper user role to modify them.
Step 3: Declaration of Twig\Extensions\TextExtension
You have to allow Twig\Extensions\TextExtension
in your /config/pacakes/twig_extensions.yaml
.
Step 4: Enable the Routes
Then, enable the routes by adding them to the /config/routes.yaml
file of your project:
Step 5: Override templates
It is strongly recommended to use the Override Templates from Third-Party Bundles feature to integrate fully with your site.
For this, simply, create the following structure /templates/bundles/c975LContactFormBundle/
in your app and then duplicate the file layout.html.twig
in it, to override the existing Bundle file.
In layout.html.twig
, it will mainly consist to extend your layout and define specific variables, i.e. :
The template used for sending emails is the one of c975LEmailBundle. Override it in /templates/c975LEmailBundle/emails/layout.html.twig
.
How to use
The Route name is contactform_display
so you can add link in Twig via ̀{{ path('contactform_display') }}
.
The url path is /contact
or /{_locale}/contact
, so simply access to http://example.com/contact
or http://example.com/en/contact
to display the form.
You can set the subject by using the url parameter s
i.e. http://example.com/contact?s=Subject
, the field will be readonly in the form, but, of course it can be changed via the url. The value is sanitized and given (as subject
) to the form in order to be able to change title and/or info text based on this value, i.e.
HoneyPot and delay to avoid spam
To avoid ContactFormBundle serving as an entry point to send spam, the field username
is a honeypot. It's only displayed to robots and is hidden via css to normal users. If it's filled, then it's not a user, but a bot. There is also a test for the delay used to submit the form. If the form is submitted before the defined delay then it may has not been filled by a human.
For both cases, ContactFormBundle will act as if the mail was sent, but it will not be the case.
Changing infoText
You can change the text displayed at the top of the Contact Form with the following code in your overriding template /templates/c975LContactFormBundle/layout.html.twig
:
Events dispatch
Disable "Receive copy" checkbox
You can disable the checkbox to allow user receiving a copy of the email sent, by catching the event CREATE_FORM
with the following code. It's useful, for example if the contact form is used to contact another user and you want to preserve its email address.
Set specific data in email sent
In relation with your app specification, it is possible to set specific email data (body, subject, etc.) based on the data sent in form. For this you have to create a listener with the following code:
Update redirect url
You can update the url to be redirected to, after submission of the form, with the following code:
If this project help you to reduce time to develop, you can sponsor me via the "Sponsor" button at the top :)
All versions of contactform-bundle with dependencies
c975l/config-bundle Version *
c975l/email-bundle Version *
c975l/services-bundle Version *
c975l/toolbar-bundle Version *
symfony/form Version *
symfony/security-bundle Version *
twig/intl-extra Version *