Contact / Feedback Form Plugin for Mephisto

Introduction
If you use Mephisto, a content management / blogging system written in Rails, you may well be interested in using this new plug-in. It provides a form that lets visitors to your site leave their contact details and send you messages or feedback via email.

UPDATE
Please check out information about using the contact form plugin with Mephisto Drax 0.8.

License
This plug-in was developed for the new ThoughtWorks Studios site. As I wrote it at and for work, it is copyright ThoughtWorks, 2007. However, ThoughtWorks, being generous souls, is happy for me to open source it under the Apache 2.0 licence, which pretty much means you have free reign to use it as you want.

Requirements

  • Mephisto Edge (the latest stable 0.7.3 release does not have support for Mephisto plugins)
  • Rails Edge (required by Mephisto edge)
  • ActionMailer (comes with Rails) correctly configured with SMTP server etc, so that emails can be delivered. See "Configuration" section here for more details.

Installation

ruby script/plugin install http://github.com/jcrisp/mephisto_contact_form/tree/master

or in your vendor/plugins directory for Mephisto:

git clone http://github.com/jcrisp/mephisto_contact_form/tree/master mephisto_contact_form

Make sure you restart your web server at this point so that the plugin is loaded.

Setup
1. Create a new template called 'contact_us.liquid' though the admin web interface (under the 'Design' tab).
Paste in the following code:

<H1>Contact Us</H1>
{% contactform %}
<p>{{ form.name }}<label for="author"><small>Your name</small></label></p>
<p>{{ form.email }}<label for="email"><small>Email address</small></label></p>
<p>{{ form.phone}}<label for="phone"><small>Phone number (optional)</small></label></p>
<p>{{ form.subject}}<label for="subject"><small>Subject</small></label></p>
<p>{{ form.body }}</p>
<p>{{ form.submit }}</p>
{% endcontactform %}

Feel free to modify labels, layout etc.

2. Edit

{MEPHISTO_ROOT}/vendor/plugins/mephisto_contact_form/lib/contact_notifier.rb

and put in the email address you want contact form submissions to go to.

3. Link to "/contact_form" from your site.

Any issues / questions / suggestions?
Best to post comments on this blog.

Technical Info
The contact form plugin is actually a combination of a rails plugin, a liquid block plugin and a Mephisto plugin. See this post about developing Mephisto plugins for more information.


Actions

Information

34 responses to “Contact / Feedback Form Plugin for Mephisto”

21 03 2007
Anonymous (06:56:00) :

Hi James,

For #3 "Link to "/contact_form" from your site.". How do you exactly go about doing that.

Does that mean to add a new section from the admin panel and use the contact_us.liquid as the page template.

Let me know if you could provide more specific instructions for this.

Thanks.

21 03 2007
James Crisp (08:00:00) :

No need to add a new section in the admin panel. Once the plug-in is installed, it adds a route to /contact_form to Mephisto. Say you want to link to the contact form from a page, you would add a link like this:

<a href="/contact_form">Contact Us</a>

26 03 2007
Anonymous (14:50:00) :

Hello james

thanks for your work on the contact form. it was exactly what I was looking for. Had to install a new trunk version of Mephisto to make it work - but in the final...
Cheers
Michael

P.S. Any idea how to use iframes in Rails? Is there a plugin somewhere out there in the Rails world? Or another solution?

26 03 2007
James Crisp (23:05:00) :

Hi Michael,

Thanks for your comment. Depending on your requirements, a better solution may be to use ajax and divs. See more info here:

http://www.onlamp.com/pub/a/onlamp/2005/06/09/rails_ajax.html

28 03 2007
Brian (18:44:00) :

Hi James,

I'm using 0.7.3 :-( is there a solution of some sort to actually make it work in v0.7.3?

what could I do as an alternitive.?

Thanks in advance

Brian

28 03 2007
James Crisp (19:28:00) :

Hi Brian,

I haven't tried it, and there may be more gotchas, but if you install the plug-in and then add the routes manually to Mephisto's routes.rb that are in here:

http://mephisto-contact-form-plugin.googlecode.com/svn/plugins/mephisto_contact_form/lib/plugin.rb

it may well work :-)

Also, if you set up a test database, you should be able to run the unit tests and see if anything else is lacking/broken.

Please post to tell me how it goes!

Cheers,
James

15 04 2007
Octave Z (16:38:00) :

Hello! Thanks for your plugin. It work good. How can I add a layout for this page or if it's not possible show the title of the page (ex: My Site | Contact).

Thanks in advance.

18 04 2007
josh huckabee (23:10:00) :

Hi James - great plugin!

I added a very minor modification to allow the user to update the destination email address in the plugin configuration.

The changes are listed here: http://joshhuckabee.com/mephisto_contact_form_modification

Thanks again!

9 05 2007
Philip (06:46:00) :

Thanks for a great contribution!

Now my next question is how to get plugins to load on a shared hosting situation at RailsPlayground, where "restarting my Rails app" is not an option. Hmmm....

14 05 2007
James Crisp (04:20:00) :

Hi Phillip,

Assuming your hosting is apache fast cgi, you can kill any processes running under your user called dispatch.fcgi. That should be pretty much the same as a server restart.

Cheers,
James

14 05 2007
Philip (13:19:00) :

Thanks, James.

Unfortunately, I'm still having a horrific time getting it going under stable 0.7 of Mephisto (rev. 2852, last changed 2828) and Rails 1.2.2 on my shared Linux hosting. RailsPlayground reports the following when they run via Webrick:

=> Booting WEBrick...
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:266:in `load_missing_constant': uninitialized constant Mephisto::Plugin (NameError)
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in `const_missing'
from ./script/../config/../vendor/plugins/mephisto_contact_form/lib/plugin.rb:3
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:342:in `new_constants_in'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require'
from script/../config/../vendor/plugins/mephisto_contact_form/init.rb:12:in `load_plugin'
... 21 levels...
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/server.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from script/server:3

As it happens, I get exactly the same problem on my local Win XP installation, which at least makes troubleshooting easy. :)

I seem to recall seeing this problem with another app, and it may have been the results of some change in the plugin system. I feel like I'm missing some step, as though my versions are mismatched or something. Any ideas?

Thanks,

Philip

14 05 2007
Philip (13:33:00) :

Sorry, i can't read. Is Mephisto Edge a reliable platform for one's professional Web site? It certainly sounds like I'd be better off with a stable version, but then I'm going to have to attempt your hacking suggestions in the comment to Brian above.

Should I ask Rick for a development roadmap so I can assess when I can get a stable version of Mephisto that supports this plugin? Or is such a roadmap published somewhere?

23 05 2007
James Crisp (06:44:00) :

Hi Phillip,

The last Mephisto release was almost a year ago.. I don't know when the next one is due - probably best to ask Rick as you suggest, and also get his opinion on edge stability.

James

7 06 2007
Anonymous (09:38:00) :

Hi James and thanks for your wonderful plugin,I was using it flawlessly on my mephisto trunk, now i setup a new mephisto install on mediatemple, do no tknwo why, but actually when i am trying to send emails after setting up all the things as specified i got an error page?????mmmm i checked my production.log and i've found a weird message (i am pasting here the main line from my log saving your time from reading all the rest, but i guess this is the main error)
NoMethodError (undefined method `com' for nil:NilClass):
/vendor/plugins/mephisto_contact_form/lib/contact_notifier.rb:7:in `contact_notification'

it seems something is wrong when i setup my recipients into contact notifier.

Do not know what i am doing wrong actually i specified "somename@someemailaddress.com"

it seems that it doesn't like the ".com" part of the thing:)

Any help is highly appreciated and thanks again for your wonderful contribution

19 06 2007
Dylan (22:40:00) :

Hey James,

Great plugin. I've got everything working except I'm not receiving the email. My logs show the email that is sent and I've tried configuring it to use both smtp and sendmail.

Have you got any tips for debugging ActionMailer and its configuration?

Cheers

Dylan

26 06 2007
sc0ttman (17:41:00) :

Hey everyone. I was wondering if anyone knows a way to detect in my layout when I am on the contact form? I would like to know this in order to render a tab in my css as style='selected'.
Is there anyway to know this??

ex:
{% if site.current_section.name == "Contact" %} or something like this?

22 10 2007
James Crisp - Ruby on Rails, C#, .NET, book reviews, film reviews, mind hacks, Wing Chun and the occasional personal bit. » Tips for Developing Mephisto Plugins with Liquid and Rails (16:06:06) :

[...] I was writing a contact form plugin for Mephisto, I had a lot of trouble finding documentation and ended up reading lots of code and [...]

5 12 2007
Mikel Lindsaar (12:32:32) :

Not sure why, but when I put this into to Mephisto edge on rails 1.99.1 it would return a 404 error on looking at localhost/contact_form.

I dug around the console, it was showing up on the custom_routes as well as in the $LOAD_PATH... just wasn't showing up in ActionController::Routing::Routes.routes

Handling was to put the following into the config/routes.rb file to hard code the routes in and now it works fine.


ActionController::Routing::Routes.draw do |map|

Mephisto::Routing.connect_with map do

map.contact "/contact_form",
{ :action=>"contact_form",
:controller=>"contact_form" }

map.contact "/contact_submit",
{ :conditions=>{:method=>:post},
:action=>"contact_submit",
:controller=>"contact_form"}

end
end

Hope that helps someone else.

Mikel

10 12 2007
James (21:37:42) :

Thanks Mikel for finding this and sending me a patch. I've applied it tonight to the contact form repository.

Something seems to have changed in either Edge Rails or Edge Mephisto that breaks the Mephisto plug-in API's add_route method. The problem seems to be that Mephisto route configuration (lib/mephisto/routing.rb) is now happening before plug-ins are loaded. Previously, plug-ins were loaded before Mehisto route configuration was done. I'll investigate further when I get a chance. Keen to hear ideas on a fix for add_route :-)

Cheers,
James

5 01 2008
Mark McSpadden (05:08:46) :

I'm on mephisto revision 3074 with rails 2.0.2 and the add_routes methods seem to be working. In fact, I had to use them instead of the routing patch. Just an FYI.

Thanks for the plugin!

22 01 2008
James (21:55:27) :

the email bodies are showing up in my rails application logs, causing a large amount of wasted space. Anybody know how to prevent this?

28 01 2008
James (16:54:02) :

Suggest increasing your logging level filtering in production. See:
http://maintainable.com/articles/rails_logging_tips#log-levels
James

28 01 2008
James (23:32:28) :

Mark, that's good news and thanks for dropping me a line. I've updated the code back to using add_route.
James

31 01 2008
nic (12:26:24) :

Man, I wish I could use this but I'm a rails noob and can't figure out what is wrong. When I install it I get an application error. Nothing is written in my logs when this happens either. Am I doing something wrong?

2 02 2008
James (11:02:25) :

Hey Nic,

Are you running with apache fcgi? Maybe this post might help:

http://jamescrisp.org/2006/08/19/ruby-on-rails-hosting-setup-and-migration/

Cheers,
James

9 04 2008
Roche Foo (01:31:46) :

Hey James,

Ths for the share, nice to see that the Plugin is easily extensible.

When installing i didn't see the version required while my mephisto is 0.7.2. Now i got a problem the same with Philip.

How could i unistall the plugin now?

THANKS.

Roche Foo

9 04 2008
James (10:11:50) :

Hi Roche,

To uninstall any rails plug-in you should just be able to delete the directory:
[RAILS ROOT]/vendor/plugins/[PLUGIN NAME]

James

9 04 2008
Roche Foo (20:48:03) :

Ths a billion, it works.

25 08 2008
James Crisp - C#, JRuby, Ruby on Rails, .NET, book reviews, film reviews, mind hacks, Wing Chun and the occasional personal bit. » Contact Form For Mephisto updated for Drax 0.8 (15:23:34) :

[...] Drax (version 0.8) introduces breaking changes for plugins. I’ve just finished updating the contact / feedback form plugin. It’s now working fine and tests [...]

24 11 2008
Pat Roy (08:11:49) :

Hi, I'm running Rails 2.0.2 with Mephisto Drax 0.8 with the latest version of this plugin and I can't get the /contact_form route to work. I've tried everything people recommend in the comments. No go. Anybody can help?

I get this when manually add the routes:

uninitialized constant ContactFormController

24 11 2008
Pat Roy (11:27:20) :

Nevermind I didn't have the right Mephisto version (without Engines). If you download mephisto from github the 0.8 tag won't have Engines you have to download from the master branch.

24 11 2008
James (15:19:41) :

Glad you got it sorted, and thanks for posting your solution.
James

25 11 2008
Steve Ross (05:44:25) :

If you get weird mail errors ie: "Net::SMTPSyntaxError (501 5.1.3 Bad recipient address syntax)" you may need to add this to your environments.rb: config.action_mailer.delivery_method = :sendmail Should work if you are using postfix or sendmail (postfix has a sendmail clone so you can swap it out easily)

1 12 2011
API Camps (23:11:41) :

Real excellent info can be found on weblog .