|
Let's take a look at the contents of template.php:
<html>
<head>
<title>Template Title</title>
<style type="text/css">
div.bbsLogo, a.bbsLogo {
font-family: verdana,sans-serif;
font-size: 24px;
color: #DDDDDD;
background-color: inherit;
text-align: left;
margin: 0px 0px 0px 15px;
text-decoration: none;
}
</style>
</head>
<body style="background-image:url('http://www.brainbooksoftware.com/images/bbsBg.png');
background-repeat:repeat-x;">
<div style="width:600px;margin-left:auto;margin-right:auto;">
<div class="bbsLogo">
<a class="bbsLogo" href="http://www.brainbooksoftware.com">
BRAIN BOOK SOFTWARE
</a>
</div>
INSERT FORM HERE
</div>
</body>
</html>
Pages on your website might be more complicated, however the structure of your webpages should always be consistent with that of template.php. Next, let's take a look at the 3 sections that we will be adding to template.php.
| | | | Section 1 | | | | | |
Section 1 is inserted at the start of your webpage and is responsible for the form structure and actions.
<?php
// ---------- CONFIG - BEGIN ----------
// relativePathToForm is the relative path from this webpage
// to your form.
$relativePathToForm = "FORMfields/forms/generated/contact_us.php";
// relativePathToFORMfields is the relative path from this webpage
// to your FORMfields directory.
$relativePathToFORMfields = "FORMfields";
// ---------- CONFIG - END ----------
require_once(dirname(__FILE__) . "/" . $relativePathToFORMfields
. "/FORMfields.php");
$parts = preg_split("'/\\* (BEGIN|END) - SECTION [1-3] \\*/'",
file_get_contents(dirname(__FILE__) . "/" . $relativePathToForm));
// There can be 6 parts or 7 parts depending on the version of FORMgen,
// which may or may not include the "/* BEGIN - SECTION 1 */" comment.
// In each case, the parts are formatted differently
if (sizeof($parts) == 6) {
$section1 = "?>" . $parts[0] . " ?>";
$section2 = $parts[2] . " ?>";
$section3 = $parts[4] . " ?>";
} else if (sizeof($parts) == 7) {
$section1 = $parts[1];
$section2 = $parts[3] . " ?>";
$section3 = $parts[5] . " ?>";
}
// Remove the require_once statements that include FORMfields.php as the
// path may not be correct
$section1 = preg_replace("'require_once\\(.*?FORMfields\\.php\"\\)\\;'", "", $section1);
eval($section1);
?>
Note: In our example, we assume that our generated form is located at http://www.yourdomain.com/FORMfields/forms/generated/contact_us.php and we assume our existing webpage is located at http://www.yourdomain.com/template.php. The form and the webpage can be in any locations, however we have to configure the $relativePathToForm accordingly. For example, if your form and existing webpage are located in the same directory, then $relativePathToForm = "contact_us.php". Or instead, if your form is located at http://www.yourdomain.com/forms/my_form.php and your webpage is located at http://www.yourdomain.com/template.php then $relativePathToForm = "forms/my_form.php"
| | | | |
| | | | Section 2 | | | | | |
Section 2 is inserted in the <head> tag of your webpage and is responsible for including the CSS templates and handling form redirection.
<?php eval($section2); ?>
| | | | |
| | | | Section 3 | | | | | |
Section 3 is inserted in the <body> tag in the location where you'd like your form to be displayed.
<?php eval($section3); ?>
| | | | |
So, by inserting the above 3 sections into template.php, we get our merged webpage:
<?php
// ---------- CONFIG - BEGIN ----------
// relativePathToForm is the relative path from this webpage
// to your form.
$relativePathToForm = "FORMfields/forms/generated/contact_us.php";
// relativePathToFORMfields is the relative path from this webpage
// to your FORMfields directory.
$relativePathToFORMfields = "FORMfields";
// ---------- CONFIG - END ----------
require_once(dirname(__FILE__) . "/" . $relativePathToFORMfields
. "/FORMfields.php");
$parts = preg_split("'/\\* (BEGIN|END) - SECTION [1-3] \\*/'",
file_get_contents(dirname(__FILE__) . "/" . $relativePathToForm));
// There can be 6 parts or 7 parts depending on the version of FORMgen,
// which may or may not include the "/* BEGIN - SECTION 1 */" comment.
// In each case, the parts are formatted differently
if (sizeof($parts) == 6) {
$section1 = "?>" . $parts[0] . " ?>";
$section2 = $parts[2] . " ?>";
$section3 = $parts[4] . " ?>";
} else if (sizeof($parts) == 7) {
$section1 = $parts[1];
$section2 = $parts[3] . " ?>";
$section3 = $parts[5] . " ?>";
}
// Remove the require_once statements that include FORMfields.php as the
// path may not be correct
$section1 = preg_replace("'require_once\\(.*?FORMfields\\.php\"\\)\\;'", "", $section1);
eval($section1);
?>
<html>
<head>
<title>Template Title</title>
<?php eval($section2); ?>
<style type="text/css">
div.bbsLogo, a.bbsLogo {
font-family: verdana,sans-serif;
font-size: 24px;
color: #DDDDDD;
background-color: inherit;
text-align: left;
margin: 0px 0px 0px 15px;
text-decoration: none;
}
</style>
</head>
<body style="background-image:url('http://www.brainbooksoftware.com/images/bbsBg.png');
background-repeat:repeat-x;">
<div style="width:600px;margin-left:auto;margin-right:auto;">
<div class="bbsLogo">
<a class="bbsLogo" href="http://www.brainbooksoftware.com">
BRAIN BOOK SOFTWARE
</a>
</div>
<?php eval($section3); ?>
</div>
</body>
</html>
Here are links to download the example source code: contact_us.php, template.html, template.php. Please recall that contact_us.php should be placed at http://www.yourdomain.com/FORMfields/forms/generated/contact_us.php, template.html placed at http://www.yourdomain.com/template.html and template.php placed at http://www.yourdomain.com/template.php.
| |