th3mouk / contact-bundle
Symfony Th3MoukContactBundle to factorize contact form generation throught websites.
Installs: 278
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/symfony: ^2.3
- th3mouk/mailer: ^1.0
Requires (Dev)
- fabpot/php-cs-fixer: ^0.5|^1.0
This package is auto-updated.
Last update: 2021-10-04 21:12:25 UTC
README
This Symfony bundle providing base for manage contact form.
The aim is to factorise website contact form.
Installation
php composer.phar require th3mouk/contact-bundle ^1.2
Add to the appKernel.php
:
new Th3Mouk\ContactBundle\Th3MoukContactBundle(),
Update your routing.yml
application's file.
th3mouk_contact: resource: "@Th3MoukContactBundle/Resources/config/routing.yml" prefix: /contact
Configure entities and templates in config.yml
th3mouk_contact: datas: from: noreply@domain.com to: - test.mail@domain.com subject: Contact request from your website class: entity: AppBundle\Entity\Contact formType: AppBundle\Form\ContactType templates: application: AppBundle:Contact:contact.html.twig mailer: AppBundle:Contact:mail.html.twig flash_messages: success: contact.mail.success error: contact.mail.error
Usage
Create Contact
entity that implement the Th3Mouk\ContactBundle\Entity\ContactInterface
with the app/console d:g:entity
.
Generate the relative FormType: app/console d:g:f AppBundle:Contact
.
Create two template for frontend and mail, you have access to form
object to draw your form, and your contact
object in the mail template.
Check the following exemples:
Exemple of ContactType
namespace AppBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class ContactType extends AbstractType { /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name') ->add('adress') ->add('zipCode') ->add('city') ->add('phone') ->add('email', 'email') ->add('message') ; } /** * @param OptionsResolver $resolver */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'AppBundle\Entity\Contact', )); } /** * @return string */ public function getName() { return 'app_contact_type'; } }
Exemple of Form Template
<h1>Contact Request</h1> {{ form_start(form) }} {{ form_row(form.name) }} {{ form_row(form.adress) }} {{ form_row(form.zipCode) }} {{ form_row(form.city) }} {{ form_row(form.phone) }} {{ form_row(form.email) }} {{ form_row(form.message) }} <div class="form-group"><button type="submit" class="btn-default btn">Submit</button></div> {{ form_rest(form) }} {{ form_end(form) }}
Exemple of Mail Template
{{ contact.name }}<br> {{ contact.adress }}<br> {{ contact.zipCode }}<br> {{ contact.city }}<br> {{ contact.phone }}<br> {{ contact.email }}<br> {{ contact.message }}
Sonata Integration Exemple
First use the app/console sonata:admin:generate
command.
Then add the service configuration:
app.admin.contact: class: AppBundle\Admin\ContactAdmin arguments: [~, AppBundle\Entity\Contact, SonataAdminBundle:CRUD] tags: - {name: sonata.admin, manager_type: orm, label: Contacts}
Add the admin group on the dashboard:
sonata.admin.group.contact: label: Contact label_catalogue: SonataPageBundle icon: '<i class="fa fa-envelope"></i>' items: - app.admin.contact roles: [ ROLE_ADMIN ]
Don't forget to add this group on a block:
sonata_admin: dashboard: blocks: - { position: left, type: sonata.admin.block.admin_list, settings: { groups: [...sonata.admin.group.contact...] }}
You're done! 👍
Events
You have access to two events before and after mail was send :
Please
Feel free to improve this bundle.