Include text

The include text is what turns an ordinary HTML page into a twzContact form page. Usually the page containing your contact form should have a .php file extension.

Contact page

Most of the pages of your web site will have a common look, with the same general layout, navigation links, and so on. The only thing different about each page is the specific page content. When creating a twzContact form for your site, you start with the same template as the rest of your pages, but at the place where the content goes, just insert this text:

<?php require_once('twzContact.php'); ?>

When the page is uploaded to the server and viewed in a browser, twzContact will create the contact form for you, based on the settings file and the CSS styles you have defined.

Non-standard settings file

If you want to use a different settings file than the default, insert this text instead:

<?php define('INI_FILE', '../'); require_once('twzContact.php'); ?>

Table layout

For versions prior to 2.3.0, twzContact rendered the contact form as an HTML table. From v2.3.0 the default is a tableless layout using <label> and <div> tags. If you want your form to be rendered as a table, you'll need to define a USE_TABLES constant, like this:

<?php define('INI_FILE', '../'); define('USE_TABLES', true); 
require_once('twzContact.php'); ?>

Javascript validation

twzContact currently only offers server-side form validation. If you want to include your own client-side validation using Javascript, you can define a JS_ONSUBMIT constant containing the Javascript to call on form submission. The script should return either true (to allow form submission) or false (to stop form submission). No double quotes should be included. A typical example would be:

<?php define('JS_ONSUBMIT', 'return checkForm();'); 
require_once('twzContact.php'); ?>

Purists may prefer to use js on the page that unobtrusively adds the onsubmit/onclick event.

Additional extensions

Additional HTML tags are required if you're using a 'calendar' field on your form (see the sample form.php for further information).

You can also include your own custom PHP code in the page if required. If you want to perform custom checks on the submitted data before it's accepted, you can do so with a custom pre-processing function. If you want to perform additional work on the submitted data after successful submission (for example save it to a database, or send an email to the visitor, or even replace the email normally sent by twzContact), you can do so with a custom processing function.


Here is a very simple example of a complete web page with contact form:


  <title>Contact us</title>

  <link rel="stylesheet" href="mystyle.css" type="text/css" />



  <h2>Contact Us</h2>
  Please complete the following form to contact us
  <?php require_once('twzContact.php'); ?>


Using .html file extension

As mentioned above, your contact page will normally require a .php file extension (for example ContactUs.php). If you really want the page to appear with a .html extension (eg ContactUs.html), there a several ways to achieve this. The following examples are for an Apache web server; you may need to consult your server administrator to determine the best way to do this for your site.

Rewrite .html to .php

This is the recommended method. Your contact page still requires a .php extension (eg ContactUs.php), but you can refer to it as ContactUs.html. To do this, edit or create a file on the server called .htaccess, containing:

RewriteEngine On
RewriteRule ^ContactUs.html$ /ContactUs.php [L] 

When a browser asks for ContactUs.html, the server actually serves up ContactUs.php. To your visitor it looks like the page is named ContactUs.html.

Make PHP parse all .html files

This method is not recommended, because it sends all .html files through PHP, and can add an unnecessary workload to the server. Edit or create your .htaccess with the following:

AddType application/x-httpd-php .html
AddHandler x-httpd-php .html 

Testing without PHP

Your contact form will only work as intended when viewed on a web server. If your local computer doesn't have web server software installed with PHP support, you will need to upload your files to your web site to test the form properly.

However, it is still possible to tweak your CSS styles just on your local computer, rather than making a small change, then uploading your CSS over and over again until it's right. Just follow these steps:

  1. Set up twzContact on the web server as normal, and submit the form with some required fields missing. You should see the page come back with a message asking you to check the form and try again.
  2. View the source of this page in your browser (either select Page Source from the View menu, or right-click on the page and select View Page Source).
  3. Copy the code and paste it into a text editor, then save it on your computer as test.html in the same folder as the local copy of your css file.
  4. Open test.html in your browser. You can now tweak your local css styles, and refresh test.html in your browser (F5 key) to see the changes. You won't be able to submit this form - it's just a static example to show you how it will look.

Once you're happy with the look of your form, simply upload the updated css file back to the server so you can test the form properly.