, (*1)
, (*2)
This bundle provides a contact form in Symfony2., (*3)
License
This bundle is available under the MIT license., (*4)
Prerequisites
This version of the bundle requires Symfony 2.3+., (*5)
Translations
If you wish to use default texts provided in this bundle, you have to make
sure you have translator enabled in your config., (*6)
``` yaml, (*7)
app/config/config.yml
framework:
translator: ~, (*8)
For more information about translations, check the [Symfony documentation](http://symfony.com/doc/current/book/translation.html).
## Installation
Installation is a quick 6 step process:
1. Download MremiContactBundle using composer
2. Enable the Bundle
3. Create your Contact class (optional)
4. Configure the MremiContactBundle
5. Import MremiContactBundle routing
6. Update your database schema (optional)
### Step 1: Download MremiContactBundle using composer
Add MremiContactBundle in your composer.json:
```js
{
"require": {
"mremi/contact-bundle": "dev-master"
}
}
Now tell composer to download the bundle by running the command:, (*9)
``` bash
$ php composer.phar update mremi/contact-bundle, (*10)
Composer will install the bundle to your project's `vendor/mremi` directory.
### Step 2: Enable the bundle
Enable the bundle in the kernel:
``` php
For now, only Doctrine ORM is handled by this bundle (any PR will be
> appreciated :) ).
``` php
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Acme\ContactBundle\Entity\Contact"
table="contact">
<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>
</entity>
</doctrine-mapping>
YML Version:
``` yaml, (*11)
Acme\ContactBundle\Entity\Contact:
type: entity
table: contact
id:
id:
type: integer
generator:
strategy: AUTO, (*12)
Annotations Version:
``` php
<?php
// src/Acme/ContactBundle/Entity/Contact.php
namespace Acme\ContactBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Mremi\ContactBundle\Entity\Contact as BaseContact;
/**
* @ORM\Entity
* @ORM\Table(name="contact")
*/
class Contact extends BaseContact
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
The bundle comes with a sensible default configuration, which is listed below.
However you have to configure at least a recipient address., (*13)
# app/config/config.yml
mremi_contact:
store_data: false
contact_class: Mremi\ContactBundle\Model\Contact
form:
type: mremi_contact
name: contact_form
validation_groups: [Default]
subject_provider: mremi_contact.subject_provider.noop
email:
mailer: mremi_contact.mailer.twig_swift
from: []
to: [] # Required
template: MremiContactBundle:Contact:email.txt.twig
mremi_contact.email.from
allows you to set the From address of the message:, (*14)
# app/config/config.yml
mremi_contact:
email:
from:
- { address: john.doe@example.com, name: "John Doe" }
- { address: foo.bar@example.com }
mremi_contact.email.to
allows you to set the To address of the message:, (*15)
# app/config/config.yml
mremi_contact:
email:
to:
- { address: webmaster@example.com, name: "Webmaster" }
- { address: moderator@example.com }
You can also configure your favorite captcha. You have to install it by
yourself and configure it here. You can get one from these bundles:, (*16)
Or even implement your own., (*17)
# app/config/config.yml
mremi_contact:
form:
captcha_type: genemu_captcha # or any other (genemu_recaptcha, ewz_recaptcha, ...)
Now that you have activated and configured the bundle, all that is left to do is
import the MremiContactBundle routing file., (*18)
By importing the routing file you will have ready access the contact form., (*19)
In YAML:, (*20)
``` yaml, (*21)
app/config/routing.yml
mremi_contact_form:
resource: "@MremiContactBundle/Resources/config/routing.xml", (*22)
Or if you prefer XML:
``` xml
<!-- app/config/routing.xml -->
<import resource="@MremiContactBundle/Resources/config/routing.xml"/>
Note:, (*23)
In order to use the built-in email functionality, you must activate and
configure the SwiftmailerBundle., (*24)
Step 6: Update your database schema (optional)
If you configured the data storage (step 3), you can now update your database
schema., (*25)
If you want to first see the create table query:, (*26)
``` bash
$ app/console doctrine:schema:update --dump-sql, (*27)
Then you can run it:
``` bash
$ app/console doctrine:schema:update --force
You can now access to the contact form at http://example.com/app_dev.php/contact
!, (*28)
Note:, (*29)
If your are in debug mode (see your front controller), the HTML5 validation
can be disabled by adding ?novalidate=1
to the URL., (*30)
Customization
Templating
If you want to customize some parts of this bundle (views for instance), read
the Symfony documentation., (*31)
Events
The contact controller dispatches 3 events during the index action:, (*32)
- ContactEvents::FORM_INITIALIZE occurs when the form is initialized
- ContactEvents::FORM_SUCCESS occurs when the form is submitted successfully
- ContactEvents::FORM_COMPLETED occurs after saving the contact in the contact form process
Each one allows you to customize the default workflow provided by this bundle., (*33)
Contribution
Any question or feedback? Open an issue and I will try to reply quickly., (*34)
A feature is missing here? Feel free to create a pull request to solve it!, (*35)
I hope this has been useful and has helped you. If so, share it and recommend
it! :), (*36)
@mremitsme, (*37)