Giter Club home page Giter Club logo

contactbundle's Introduction

MremiContactBundle

SensioLabsInsight

Build Status Total Downloads Latest Stable Version Scrutinizer Code Quality Code Coverage

This bundle provides a contact form in Symfony2.

License

This bundle is available under the MIT license.

Prerequisites

This version of the bundle requires Symfony 2.3+.

Translations

If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config.

# app/config/config.yml

framework:
    translator: ~

For more information about translations, check Symfony documentation.

Extra form

This bundle requires the GenemuFormBundle for an easy captcha integration, so you need to configure it.

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:

{
    "require": {
        "mremi/contact-bundle": "dev-master"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update mremi/contact-bundle

Composer will install the bundle to your project's vendor/mremi directory.

Step 2: Enable the bundle

Enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Mremi\ContactBundle\MremiContactBundle(),
    );
}

Step 3: Create your Contact class (optional)

The goal of this bundle is not to persist some Contact class to a database, but you can if you want just by setting the store_data parameter to true (default false). So if you don't need to do this, you can jump to the next step.

Your first job, then, is to create the Contact class for your application. This class can look and act however you want: add any properties or methods you find useful. This is your Contact class.

The bundle provides base classes which are already mapped for most fields to make it easier to create your entity. Here is how you use it:

  1. Extend the base Contact class from the Entity folder
  2. Map the id field. It must be protected as it is inherited from the parent class.

Note:

For now, only Doctrine ORM is handled by this bundle (any PR will be appreciated :) ).

<?php
// src/Acme/ContactBundle/Entity/Contact.php

namespace Acme\ContactBundle\Entity;

use Mremi\ContactBundle\Entity\Contact as BaseContact;

class Contact extends BaseContact
{
    /**
     * @var integer
     */
    protected $id;
}
<!-- src/Acme/ContactBundle/Resources/config/doctrine/Contact.orm.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<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>

Step 4: Configure the MremiContactBundle

The bundle comes with a sensible default configuration, which is listed below. However you have to configure at least the recipient address.

# 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
        captcha_disabled:  false
        captcha_type:      genemu_captcha # or genemu_recaptcha

    email:
        mailer:            mremi_contact.mailer.twig_swift
        recipient_address: [email protected]
        template:          MremiContactBundle:Contact:email.txt.twig

Step 5: Import MremiContactBundle routing

Now that you have activated and configured the bundle, all that is left to do is import the MremiContactBundle routing file.

By importing the routing file you will have ready access the contact form.

In YAML:

# app/config/routing.yml
mremi_contact_form:
    resource: "@MremiContactBundle/Resources/config/routing.xml"

Or if you prefer XML:

<!-- app/config/routing.xml -->
<import resource="@MremiContactBundle/Resources/config/routing.xml"/>

Note:

In order to use the built-in email functionality, you must activate and configure the SwiftmailerBundle.

Step 6: Update your database schema (optional)

If you configured the data storage (step 3), you can now update your database schema.

If you want to first see the create table query:

$ app/console doctrine:schema:update --dump-sql

Then you can run it:

$ app/console doctrine:schema:update --force

You can now access to the contact form at http://example.com/app_dev.php/contact!

Note:

If your are in debug mode (see your front controller), the HTML5 validation can be disabled by adding ?novalidate=1 to the URL.

Bootstrap

Bootstrap framework v3.0.2 is loaded and used in templates provided by this bundle.

Screenshot

Customization

Templating

If you want to customize some parts of this bundle (views for instance), read the Symfony documentation.

Events

The contact controller dispatches 3 events during the index action:

  1. ContactEvents::FORM_INITIALIZE occurs when the form is initialized
  2. ContactEvents::FORM_SUCCESS occurs when the form is submitted successfully
  3. 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.

Contribution

Any question or feedback? Open an issue and I will try to reply quickly.

A feature is missing here? Feel free to create a pull request to solve it!

I hope this has been useful and has helped you. If so, share it and recommend it! :)

@mremitsme

contactbundle's People

Contributors

mremi avatar webdevilopers avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.