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.
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.
If you want to use a different settings file than the default, insert this text instead:
<?php define('INI_FILE', '../path.to.ini.file'); require_once('twzContact.php'); ?>
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', '../path.to.ini.file'); define('USE_TABLES', true); require_once('twzContact.php'); ?>
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 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:
<html> <head> <title>Contact us</title> <link rel="stylesheet" href="mystyle.css" type="text/css" /> </head> <body> <h2>Contact Us</h2> Please complete the following form to contact us <?php require_once('twzContact.php'); ?> </body> </html>
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.
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.
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
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:
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.