Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Save fields from mailer forms to the database.

branch: 0.9

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 db
Octocat-spinner-32 features
Octocat-spinner-32 lib
Octocat-spinner-32 public
Octocat-spinner-32 spec
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 database_mailer_extension.rb
README.md

Database Mailer

About

A Radiant Extension by Aissac that adds database persistence to emailed forms. It works on top of the Radiant Mailer Extension and the fields recorded to the database are user defined. The extension adds a tab to the Radiant admin interface allowing you to browse saved records.

Tested on Radiant 0.7.1, 0.8 and 0.9 RC1.

Check out the screencast

Features

  • Save posted form fields and entire mail message to the database
  • Save e-mail attachments using paperclip
  • Configurable save-to-database for mailer forms
  • Add fields to be saved without loosing data
  • Admin interface to browse saved records
  • Export data to CSV and XLS

Important Notice!

The git branches on this repository hold stable versions of the extension for older versions of Radiant CMS. For example the 0.8 branch is compatible with Radiant 0.8.

To checkout one of these branches:

git clone git://github.com/Aissac/radiant-database-mailer-extension.git vendor/extensions/database_mailer
cd vendor/extensions/database_mailer
git checkout -b <branch-name> origin/<remote-branch-name>

As an example if you're working on Radiant 0.8 you will need to checkout the 0.8 branch:

cd vendor/extensions/database_mailer
git checkout -b my_branch origin/0.8

Installation

Radiant Database Mailer Extension has three dependecies, the Radiant Mailer Extension, the will_paginate gem/plugin and the paperclip gem/plugin

Install the mailer extension:

git clone git://github.com/radiant/radiant-mailer-extension.git vendor/extensions/mailer

Note

At the time being you will need Aissac's version of the Radiant Mailer Extension, as it incorporates sending e-mails with attachments.

the will_paginate gem/plugin:

git clone git://github.com/mislav/will_paginate.git vendor/plugins/will_paginate

or

sudo gem install will_paginate

and the paperclip gem/plugin

git clone git://github.com/thoughtbot/paperclip.git vendor/plugins/paperclip

or

sudo gem install paperclip

Next edit config/environment.rb and add desired fields to be recorded:

DATABASE_MAILER_COLUMNS = {
  :name => :string,
  :message => :text,
  :email => :string
}

And finally add the Database Mailer Extension:

git clone git://github.com/Aissac/radiant-database-mailer-extension.git vendor/extensions/database_mailer

Migrate and update the extension:

rake radiant:extensions:database_mailer:migrate
rake radiant:extensions:database_mailer:update

Configuration

Adding fields to the DATABASE_MAILER_COLUMNS hash and re-running rake radiant:extensions:database_mailer:migrate nondestructively adds fields to be saved. Fields removed from the hash are not deleted.

Look at the Mailer Extension README for information on how to configure mail delivery.

If you set save_to_database to false in the Mailer config, saving to the database is skipped and just mail delivery takes place. Example (in the mailer page part):

subject: From the website of Whatever
from: noreply@example.com
redirect_to: /contact/thank-you
save_to_database: false
recipients:
  - one@one.com
  - two@two.com

Any attachments that the e-mail might have will be saved on the file system. They can be downloaded from the details page of every record.

If you want to take advantage of the blob field you need to create a email page part. The blob field keeps the sent version of the email.

Fields that are not specified by DATABASE_MAILER_COLUMNS are silently ignored.

Usage

Create your Mailer pages and make sure to use the same field names:

<r:mailer:form>
  <label for="name">Name:</label><br/>
  <r:mailer:text name="name" /><br/>

  <label for="email">Email:</label><br/>
  <r:mailer:text name="email" /><br/>

  <label for="message">Message:</label><br/>
  <r:mailer:textarea name="message" /> <br/>

  <label for="attachment">Image:</label><br/>
  <r:mailer:file name="attachment" /><br/>

  <input type="submit" value="Send" />
</r:mailer:form>

Create the mailer page part:

subject: From the website of Whatever
from: noreply@example.com
redirect_to: /contact/thank-you
recipients:
  - one@one.com
  - two@two.com

Create an email page part (to take advantage of the blob field):

<r:mailer>
  Name: <r:get name="name" />
  Email: <r:get name="email" />
  Message: <r:get name="message" />
</r:mailer>

Contributors

Something went wrong with that request. Please try again.