Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Contact Bundle Laravel Package

mremi/contact-bundle

Symfony2 bundle that adds a ready-to-use contact form with optional Contact entity, configurable routing and translations. Install via Composer, enable the bundle, configure it, import routes, and optionally update your DB schema.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require mremi/contact-bundle
    

    Add to AppKernel.php:

    new Mremi\ContactBundle\MremiContactBundle(),
    
  2. Enable Translations Ensure framework.translator is enabled in config.yml (as per README).

  3. First Use Case Generate a basic contact form in a controller:

    use Mremi\ContactBundle\Form\Type\ContactType;
    
    $form = $this->createForm(ContactType::class);
    

Where to Look First

  • Configuration: Resources/config/services.yml (default services).
  • Form Type: Form/Type/ContactType.php (customization entry point).
  • Controller Example: Controller/ContactController.php (basic workflow).

Implementation Patterns

Core Workflow

  1. Form Submission

    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        $contact = $form->getData();
        $em->persist($contact);
        $em->flush();
    }
    
  2. Customizing Fields Extend ContactType to add/remove fields:

    use Mremi\ContactBundle\Form\Type\ContactType as BaseContactType;
    
    class CustomContactType extends BaseContactType {
        public function buildForm(FormBuilderInterface $builder, array $options) {
            $builder->add('custom_field', TextType::class);
        }
    }
    
  3. Email Handling Override the default mailer service (see services.yml):

    mremi_contact.mailer:
        class: AppBundle\Service\CustomMailer
        arguments: ['@mailer']
    
  4. Validation Add constraints to the Contact entity (e.g., NotBlank for required fields).

Integration Tips

  • Twig Integration Render the form in a template:

    {{ form_start(form) }}
        {{ form_widget(form) }}
        <button type="submit">Send</button>
    {{ form_end(form) }}
    
  • CSRF Protection Ensure csrf_protection is enabled in ContactType (default behavior).

  • Flash Messages Use Symfony’s flash system post-submission:

    $this->addFlash('success', 'Message sent!');
    

Gotchas and Tips

Common Pitfalls

  1. Missing Translations If using default texts, ensure translator is configured and locale is set (e.g., en). Fix: Add translator.default_locale: en to config.yml.

  2. Form Not Submitting

    • Check csrf_token is included in the form (enabled by default).
    • Verify isSubmitted() and isValid() logic in the controller.
  3. Email Not Sending

    • Confirm the mailer service is properly configured in services.yml.
    • Check for typos in the to email address in the mailer service.
  4. Entity Not Persisting Ensure the Contact entity is mapped to a database table and the EntityManager is injected.

Debugging Tips

  • Log Form Data Dump form data before submission:

    dump($form->getData());
    
  • Validate Manually Test validation separately:

    $validator = $this->get('validator');
    $errors = $validator->validate($contact);
    

Extension Points

  1. Custom Mailer Extend Mremi\ContactBundle\Mailer\Mailer to modify email templates or logic.

  2. Entity Customization Override the Contact entity (e.g., add created_at timestamp):

    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity]
    class Contact {
        #[ORM\Column(type: 'datetime')]
        private $createdAt;
    
        public function __construct() {
            $this->createdAt = new \DateTime();
        }
    }
    
  3. Event Listeners Attach listeners to the contact.send event (if supported in newer versions):

    services:
        app.contact_listener:
            class: AppBundle\EventListener\ContactListener
            tags:
                - { name: kernel.event_listener, event: contact.send, method: onContactSend }
    

Configuration Quirks

  • Default Recipient The to email is hardcoded in the mailer service. Override it in services.yml:

    mremi_contact.mailer:
        arguments: ['@mailer', 'custom@example.com']
    
  • CSRF Token If disabled, ensure you manually add the token to the form:

    {{ form_hidden(form._token) }}
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui