zem_contact is a plugin which extends Textpattern with a set of custom tags supporting email contact forms. Its original creator is Alex Shiels, now a member of Team Textpattern and one of Textpattern’s core developers. After a period of orphanage, zem_contact_reborn is now developed by various members of the Textpattern community and hosted at Stuart Butcher’s Bombsite.
Out of the box, zem_contact supports entry fields for various user supplied data such as e-mail addresses, single- and multiline text inputs, check boxes and radio buttons. But what, if you wanted to include other data elements stemming from an article’s properties or from other server data sources into the email as well? Imagine a situation where it would come handy to include the value of a custom article field into the message…
Applying lessons learned from a previous piece, Textpattern tags in tags, a little clutch of PHP injects data pieces into the email without requiring a HTML form element as a launchpad.
Making use of the infinite envelope
First, we need to read the value of a custom field which will become part of the email’s body:
$value = custom_field (array( 'name' => 'custom1' ));
All contents of the email body are kept in a global PHP array named
$zem_contact_form which is indexed by the
label attribute of the various form field tags that come with zem_contact. Adding another member to the array requires nothing more than a simple statement using any unused descriptive string (e.g. „Custom Field 1“) as the array index:
global $zem_contact_form; $zem_contact_form['Custom Field 1'] = $value;
Combining the two snippets above with the common static tags results in a Textpattern form containing all the necessary markup for both user input and web server generated data:
<txp:php> global $zem_contact_form; $zem_contact_form['Custom 1'] = custom_field (array( 'name' => 'custom1' )); </txp:php> <txp:zem_contact_form to="email@example.com" subject="contact" />
Now, if only the subject line could also act more dynamically. A computed „to:“ address might also be of interest…
But that’ll be another story.