Textpattern tips, tutorials and code snippets

Support ticket system

Here is a nice method of creating a simple support ticket system using the zem_contact_reborn plugin and a little PHP.

The example code features a relatively simple contact form with some PHP code which sets a random number that is passed on in the topic of the contact email.

  1. Download and install zem_contact_reborn
  2. Activate the plugin

Place the code in your article

 <txp:zem_contact label="" 
subject='Letter form site <txp:site_name />'

label="Your name:"
name="name" break="" size="40" /><br /><br />

label="Your email:"
name="zemail" break="" size="40" /><br /><br />

label="Your phone:"
name="name" break="" size="20" /><br /><br />

label="Choose topic of mail:" 
required="yes" name="reciever"/>
<br /><br />
 <txp:zem_contact_textarea cols="40" label="Your message:" name="message" break=""/><br /><br />

 <txp:if_variable name="random_ticket"><txp:else />
 variable(array('name' =>'random_ticket', 'value' => $r ));

 <txp:zem_contact_secret name="zem_contact_ticket" label="Message number">
 <txp:variable name="random_ticket" />

 <txp:zem_contact_submit label="Send message" /><br />


The code is placed in your article, although you could use it in your page template instead and call it via output_form. Note that for this example, two spaces have been added to avoid Textile processing. More about Textile processing in the Turn off Textile in your article tip.

Create a form called ticket_thanks

We recieved your message under number #
<b><txp:php> echo $_SERVER["random_ticket"]; </txp:php></b>.
We will answer as soon as possible!

Place this code in a new form and save it as ticket_thanks and type misc.

For more information, see this forum post.

1 Comment Comment feed

Not being familiar with PHP, is it not possible that the same number would be generated for more than one ticket? (Regardless, nice bit of code — thanks.)

Add a comment

Use Textile help to style your comments