The dmContactPlugin allows to display a typical contact form.
By default, contact requests sent with the form are stored in database.
The plugin packages a Diem front widget and an admin interface to manage contact requests.
Integrates recaptcha validation.
See it in action on the contact page
git clone git://github.com/ornicar/dmContactPlugin.git plugins/dmContactPlugin
class ProjectConfiguration extends dmProjectConfiguration { public function setup() { parent::setup(); $this->enablePlugins(array( // your enabled plugins 'dmContactPlugin' ));
php symfony doctrine:generate-migrations-diff
php symfony doctrine:migrate
php symfony dm:setup
Open the front "Add" menu, and drag&drop a contact/form widget somewhere on your site.
Open Content->Feedback->Contacts on admin menu.
This step is facultative, but will help you fighting against spam.
Add this configuration in
apps/front/config/app.yml
all:
recaptcha:
# get your recaptcha keys on http://recaptcha.net/api/getkey
public_key: 6LeefAkAAAAAAF-this-is-a-dummy-public-key
private_key: 6LeefAkAAAAAA-this-is-a-dummy-private-key
enabled: true
You will need to get API keys from the recaptcha website. It's free.
You may just use CSS if the default outputed HTML looks fine to you.
Or you can override the form template by copying
dmContactPlugin/modules/dmContact/templates/_form.php
to
apps/front/modules/dmContact/templates/_form.php
The default form is quite basic. Let's say you wanna add a "subject" field.
Add these lines in your project schema
config/doctrine/schema.yml
DmContact:
columns:
subject: { type: string(255), notnull: true }
Then run the required doctrine migrations and setup your project
php symfony doctrine:generate-migrations-diff
php symfony doctrine:migrate
php symfony dm:setup
The DmContact model and form are now up to date and contain the subject field. We still have to display the on front and admin.
Copy
dmContactPlugin/modules/dmContact/templates/_form.php
to
apps/front/modules/dmContact/templates/_form.php
then add the "subject" field somewhere, for example just after the form tag.
echo $form->open(); echo $form['subject']->label()->field()->error();
Copy
dmContactPlugin/modules/dmContactAdmin/config/generator.yml
to
apps/admin/modules/dmContactAdmin/config/generator.yml
and paste this configuration inside:
generator:
param:
config:
list:
display:
- '=name'
- subject
- email
- body
- created_at
- updated_at
form:
display:
NONE: [name, email]
Body: [subject, body]
Learn more about symfony admin generator.
you can override the DmContact model in your project
lib/model/doctrine/dmContactPlugin/DmContact.class.php
and the DmContactForm form in your project
lib/form/doctrine/dmContactPlugin/DmContactForm.class.php
Listen to the 'dm_contact.saved' event in
apps/front/config/frontConfiguration.class.php
require_once(dm::getDir().'/dmFrontPlugin/lib/config/dmFrontApplicationConfiguration.php'); class frontConfiguration extends dmFrontApplicationConfiguration { public function configure() { $this->dispatcher->connect('dm_contact.saved', array($this, 'listenToContactSavedEvent')); } public function listenToContactSavedEvent(sfEvent $e) { $contact = $e['contact']; // do something with the freshly saved $contact } }
Open issues
Closed issues
dmContactPlugin, created on January 25, 2010 by Thibault D, used by 1433 projects
RenatoJuly 1, 2010 4:06 PM
Hi, I get the error Could not generate migration classes from difference, when running doctrine:generate-migrations-diff
JérémyApril 13, 2011 1:49 PM
It's normal, nothing has changed in your schema.yml