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 Form Bundle Laravel Package

c33s/contact-form-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle Add to composer.json:

    "require": {
        "vworldat/contact-form-bundle": "^1.0"
    }
    

    Enable in config/bundles.php:

    return [
        // ...
        Vworldat\ContactFormBundle\VworldatContactFormBundle::class => ['all' => true],
    ];
    
  2. Configure the Bundle Update config/packages/vworldat_contact_form.yaml (or create it):

    vworldat_contact_form:
        email:
            from: 'contact@example.com'
            to: 'team@example.com'
            subject: 'New Contact Form Submission'
        database:
            enabled: true  # Save submissions to Propel
    
  3. First Use Case: Embed a Basic Form In a Twig template (e.g., contact.html.twig):

    {{ render(controller('VworldatContactFormBundle:Default:form')) }}
    

    This auto-generates a form with validation (name, email, message).


Implementation Patterns

Common Workflows

  1. Custom Form Fields Extend the default form type by creating a custom service:

    # config/services.yaml
    services:
        App\ContactForm\CustomFormType:
            tags: ['contact_form.form_type']
    

    Define fields in buildForm():

    $builder->add('phone', TextType::class, ['required' => false]);
    
  2. Dynamic Recipients Override the email recipient via a listener:

    // src/EventListener/ContactFormListener.php
    public function onSubmit(ContactFormEvent $event) {
        $event->setRecipient('support@' . $event->getFormData()->getDomain());
    }
    

    Register in services.yaml:

    services:
        App\EventListener\ContactFormListener:
            tags: ['kernel.event_listener', { event: 'contact_form.submit', method: 'onSubmit' }]
    
  3. Propel Integration Ensure Propel schema matches the form fields. Example schema (schema.xml):

    <table name="contact_form_submissions" phpName="ContactFormSubmission">
        <column name="name" type="VARCHAR" size="255" required="true" />
        <column name="email" type="VARCHAR" size="255" required="true" />
        <!-- Add custom fields -->
    </table>
    
  4. Twig Embedding Pass options to the form:

    {{ render(controller('VworldatContactFormBundle:Default:form', {
        'action': path('app_contact_submit'),
        'form_options': { 'attr': { 'class': 'my-custom-form' } }
    })) }}
    

Gotchas and Tips

Pitfalls

  1. Propel Schema Mismatch

    • If fields in the form don’t match the Propel schema, submissions won’t save.
    • Fix: Run php app/console propel:build --all after schema changes.
  2. Email Configuration

    • The from email must be valid or emails may fail silently.
    • Tip: Use a transactional email service (e.g., Mailgun, SendGrid) for reliability.
  3. Validation Overrides

    • Default validation is strict (e.g., email format). To relax:
    # config/packages/vworldat_contact_form.yaml
    vworldat_contact_form:
        validation:
            email: ~  # Disables email validation
    
  4. CSRF Token Issues

    • If the form submits without CSRF protection, ensure your Twig template includes:
    {{ form_start(form, { attr: { 'novalidate': 'novalidate' } }) }}
    {{ form_widget(form._token) }}
    

Debugging

  • Check Events: Use debug:event-dispatcher to verify listeners are attached:
    php bin/console debug:event-dispatcher contact_form
    
  • Log Submissions: Enable Propel logging in config/packages/propel.yaml:
    propel:
        logging: true
    

Extension Points

  1. Custom Form Actions Override the controller:

    # config/routes.yaml
    app_contact_submit:
        path: /contact
        controller: App\Controller\CustomContactController::submitAction
    

    Extend Vworldat\ContactFormBundle\Controller\DefaultController.

  2. Async Processing Use a message queue (e.g., Symfony Messenger) to decouple form submission from email sending:

    // src/Message/HandleContactForm.php
    public function __invoke(ContactFormMessage $message) {
        $this->mailer->send($message->getEmail());
    }
    
  3. Multi-Language Support Translate form labels/placeholders via translation files:

    # translations/messages.en.yaml
    contact_form:
        name: 'Your Name'
        email: 'Your Email'
    
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