Monday, March 19, 2007

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.

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://mephisto-contact-form-plugin.googlecode.com
/svn/plugins/mephisto_contact_form

or in your vendor/plugins directory for Mephisto:

svn checkout http://mephisto-contact-form-plugin.googlecode.com
/svn/plugins/mephisto_contact_form 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.

23 comments:

Anonymous said...

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.

James Crisp said...

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>

Anonymous said...

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?

James Crisp said...

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

Brian said...

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

James Crisp said...

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

Octave Z said...

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.

josh huckabee said...

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!

Philip said...

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....

James Crisp said...

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

Philip said...

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

Philip said...

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?

James Crisp said...

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

Anonymous said...

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

Dylan said...

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

sc0ttman said...

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?

Jonathan said...

@sc0ttman:
You already have the functionality of marking the current section as class="selected", check out trunk and also search on the google group. Here's the ticket that closes this feature request

free ps3 said...

Thanks for the nice post!

E. James said...
This post has been removed by the author.
E. James said...
This post has been removed by the author.
E. James said...

I was hoping those would delete completely :) Here is the consolidation:

got the edge version to try out your plugin, I followed the directions, installed the plugin, restarted, added the template (contact_us.liquid), then modified the notifier.

However I get a 404 when I go to /contact_us??

So after jumping into script/console I see that the plugin is loading "vendor/plugins/mephisto_contact_form/lib" by checking the $LOAD_PATH variable.

Then I checked Mephisto::Plugin.custom_routes to see if the route was loaded, I get this:

[["contact_form", {:controller=>"contact_form", :action=>"contact_form"}], ["contact_submit", {:conditions=>{:method=>:post}, :controller=>"contact_form", :action=>"contact_submit"}]]

I'm lost, it should be routing, but instead this dumps out:

404 Not Found [http://localhost/contact_form]


Any ideas?

James Crisp said...

Unfortunately blogger has a bug and doesn't send me notification emails any more.

Please post comments here:
http://jamescrisp.org/2007/03/19/contact-feedback-form-plugin-for-mephisto/

Cheers,
James

African safari vacation said...

I need a contact form that can be customized with an African theme for my African safari and vacation blog.