FORMfields, the premiere web framework
Login
Support Home | Knowledge Base | Documentation | Forums | Contact Us
Info
FORMfields & FORMgen :: Formatting

Creating a Template For Your Form So Updates In FORMgen Don't Destroy the Formatting

(3879 views. Last Updated: 2007-10-19 12:21 PM)

Here is an example of how to create a template for your FORMfields form so that you can make changes to this form using FORMgen and still have the layout of the form remain the same.

In this example we will assume that you have a very basic webpage called template.php that is located in FORMfields/forms and that template.php looks like:
<html>

<head>
<title>Template Title</title>
</head>

<body>
</body>

</html>

Furthermore, we will assume that your generated form is FORMfields/forms/generated/my_form.php. To add my_form.php to template.php, edit template.php and insert the following 3 code areas:
<?php

    
// ---------- CONFIG - BEGIN ----------

    // relativePathToForm is the relative path from this webpage
    // to your form.
    
$relativePathToForm "generated/my_form.php";

    
// relativePathToFORMfields is the relative path from this webpage
    // to your FORMfields directory.
    
$relativePathToFORMfields "..";
    
    
// ---------- 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); ?>
</head>

<body>
<?php eval($section3); ?>
</body>

</html>
Info
Support | Earn Money
Copyright © 2005-2019 Brain Book Software LLC.
Built with FORMfields, the premiere web framework.