Email contact forms

Email contact forms are not included in the Textpattern core, but adding a contact form to your site is very easy with the excellent zem_contact_reborn plugin. Here is a short rundown to get you started.

  1. Download the plugin
  2. Download the required zem_contact_lang
  3. Optionally, download the anti-spam plugin pap_contact_cleaner
  4. Install and activate the plugins. In our example (used on this site) we did not install pap_contact_cleaner

Create a simple email contact form

To get started, you only need a simple tag to create a simple contact form: <txp:zem_contact to="recipient at example.com" />

Place the code in your page template, and of course change the email recipient (you!). ZCR will create a simple contact form, including error checking (invalid email addresses or missing information).

A more complex contact form

ZCR makes it easy to pick and choose the field types you want in your contact form.

<txp:zem_contact to="mail@txptips.com" thanks_form="contact_thanks">
<txp:zem_contact_serverinfo name="REMOTE_ADDR" label="IP number" />
<txp:zem_contact_serverinfo name="HTTP_USER_AGENT" label="Browser" />
<ul class="commentsform">
<li><txp:zem_contact_text label="Your Name:" required="1" break="" /></li>
<li><txp:zem_contact_email label="Your Email:" required="1" break="" /></li>
<li><txp:zem_contact_textarea label="Message:" cols="30" rows="10" required="1" break="" /></li>
<li><txp:zem_contact_submit label="Send" /></li>
</ul>
</txp:zem_contact>

The above example is what we use on the TXP Tips contact form. To explain some of the features:

  • The first two txp:zem_contact_serverinfo tags send the IP number and browser of the form sender
  • Wrapping the form in a ul class="commentsform" and each tag in a li allows us to style the form in the same way as the comments on the site. In addition, we are able to style the error messages in the same way as the comments for the TXP Tips (try clicking “send” on the contact form without entering anything to see how it works)
  • required="1" allows us to define which fields are required (note that by default some of the tags are required)

Display a custom message after the form is sent

In the complex example, you might see this in the first line: thanks_form="contact_thanks". This overrides the default ZCR thanks message that is displayed after the form has been sent. Our contact_thanks form looks like this:

<p class="red">Thank you for contacting us. Your message has been sent.</p>

There are many other ways of using ZCR, including as product order forms. For more information, read the plugin help.

comments powered by Disqus