Module - Headline Rotator

I've worked on a few projects recently that had the need for a bespoke form or three. Also, I've never been entirely happy with the default Joomla! contact form. Sure, it has lots of options but mostly I just want to be able to offer visitors a quick method to email from the site and I want to be able to style that page with more flexibility than the default option offers. Sometimes I might want a form with 30 fields, other perhaps only 2 or 3.

I've used the excellent Fabrik component for a couple of projects and it could certainly have achieved what I wanted to do but it is so extensive that it would have been the very definition of overkill... Instead I finally bit the proverbial bullet and sat down to write a little module that would be all things to all men (and women) - or at least something to somebody, even if that's only me!

Panoramics

Ultra-wide photographic images
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis dui velit.

Photo Editing

Image editing for special effects
Pellentesque libero lacus, elementum sed, interdum porttitor, consectetur.

Photography

Photography services of all types
Curabitur dolor. Morbi feugiat enim nec urna. Curabitur mollis arcu vel nulla.

Websites

Website design, hosting & maintenance.
Suspendisse hendrerit commodo neque. Pellentesque sapien felis, facilisis sed.

Why a module and not a component? Well, modules feel smaller and simpler to me, which is what I felt was needed. Also there would be a need for a few parameters, but only a few. Plus, I envisaged the possibility of several copies of the module existing in a site where different forms would be needed, and keeping them together on the module page seems more efficient. I also like the added flexibility that the module could be placed into the content/article with the loadposition tag or used in a module position. Having the form embedded in an article in that way gives total flexibility over its presentation and any surrounding content that you want with it.

So, what does the finished module do?

Basically, you can write your own HTML form, embed it into an article, and choose who will receive the completed form by email.

The Parameters

mod_custom-form parametersThere are only 5 parameters, and the module will function just fine without setting any of them.

  1. Destination email addresses: here you can write a comma separated list of email addresses and the completed form will be sent to them all. If you leave this field blank the email will be sent to the Joomla! admins who are set to receive system emails
  2. Module title: If you enter somethnig here it will appear in the content. You should include any tags like <h2> etc. The actual module title will still be used if the module is used in a normal module position, this one is only for embedding in an article.
  3. Popup mail confirmation: if enabled the user will see a popup after they've completed and sent the form saying something along the lines of 'Thankyou name, your email has been sent to sitename'. Whether this is enabled or not the user will still see a confirmation web page. Both the confirmation page and the popup will include a failure message if the email doesn't get sent (eg. if your mail srttings in the global configuration are set wrongly).
  4. 4 - Verbose logging: not for use in final production. I tend to include some form of data dump while I'm writing these things so that I can check on variables etc. If you enable this it will give a dump of the GET and POST variables, show the path to the current page etc.
  5. 5 - Module class suffix: an obligatory parameter which is usually used to style modules in normal module positions with template specific styles.

The writing of the form needs to be done by you, and the code to edit is toward the end of the mod_custom-form.php file. If you're not familiar with forms I suggest some digging around the W3Schools website and perhaps Googling for some extra tips.

One neat touch is that the field names in the form are tweaked by the code to be more readable on the finished email. Underscore characters used in field names are converted to spaces, and capitalisation is preserved. So, if you have an input like:
<input type="text" name="Visitor_Name" size="18">
then one of the parts of your received email would be:
Visitor Name: Bob
It's not revolutionary, but it keeps things nice for the end user.

The whole module is nice and small - around 9kb. You might want a few different forms on your site, but a module can only be installed once. With that in mind I have tweaked the files and created a mod_custom-form2 and mod_custom-form3. You will need to install one for each different form that you'll be needing, although the same form can be called any number of times.

At some point, if I have the time to revisit this, I might make it a component and remove the need to edit the form code and the need to install more copies for different forms. That'll be quite a bit of extra stuff so for now it's on a back burner.

Feel free to use the module. If you can add a link to this site from somewhere nice that'd be splendid.

Comments and ideas are welcome and invited. If you use the module feel free to post a link to your example.

Happy Joomla!ing.