200 tips!!Featuring tips, tutorials and code to help you build better sites using Textpattern

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="" 
to="you@youremail.com" 
subject='Letter form site <txp:site_name />'
thanks_form="ticket_thanks">

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

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

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

 <txp:zem_contact_select
label="Choose topic of mail:" 
break="" 
list=",
Error,
Questions,
Other"
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 />
 <txp:php>
 $r=mt_rand(1000,9999);
 variable(array('name' =>'random_ticket', 'value' => $r ));
 $_SERVER['random_ticket']=$r;
 </txp:php>
 </txp:if_variable>

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

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

 </txp:zem_contact>

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

<h2>Thanks!</h2>
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.

comments powered by Disqus