how to setup

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

Below are the source codes of the 7 files in this bundle. Simply create the 7 files (1 is a DOCUMENTATION file, 1 is a STYLESHEET, 1 is a JAVASCRIPT FUNCTION LIBRARY FILE, and 1 is an empty OUTPUT file) in the same folder on your server, modify your questions in the modification file, and your generic forms are ready to go. Highly recommended is that you make copies of the 5 form files, changing generic-form- to specific-use-form-, for each use that you intend to have, ever maintaining the "generic-form-" copy for future development.

Legal terms: To use this set of generic form files, please indicate the primary source of the files using appropriate URIs (which necessarily include mutford.net as the root host). Please also indicate the primary author as Jason Mutford, but attributing any modifications to the appropriate modifying author(s). Likewise, the DOCUMENTATION FILE ought to be updated to include any citations for both original author and adaptation author. Any other use constitutes plagerism. All files are ©2009-2084 mutford.net.

generic-form-modifiables.php

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

<?php

                //   |  THIS IS WHERE YOU EDIT THE NAME OF THE OUTPUT TEXT FILE ******************************************
                //   |/ NOTE: it will place the file in the same directory as this .php web source file ******************
                //  \|/ NOTE: this file will APPEND to any exist file of that name ***************************************

$outputFilename = "generic-forms-ouptut.txt";

                //  /|\
                //   |  THIS IS WHERE YOU NO LONGER EDIT ANYTHING TO YOUR SPECIFICATION **********************************
                //   |

$questions = array( 1 => 

		//   |  THIS IS THE LIST OF QUESTIONS THAT NEEDS TO BE UPDATED TO YOUR SPECIFICATION *********************
		//   |  NOTE: the last entry does not receive the comma ending - all other questions do! *****************
                //  \|/

   "Last Name",
   "First Name",
   "Phone Number",
   "Address (line 1)",
   "Address (line 2)",
   "City",
   "State (abbr.)",
   "ZIP code"

                //  /|\
                //   |  THIS IS WHERE YOU NO LONGER EDIT ANYTHING TO YOUR SPECIFICATION **********************************
                //   |  NOTE: Did you remember to leave off the comma for the last element? ******************************

    ); // end of array

$counterMax = count($questions);

?>

generic-form-interface.php

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

Note: there are both a <link> element to a stylesheet and a <script> element to an imported javascript function file. These are likewise included below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

    <link type="text/css" rel="stylesheet" href="/styles.css" />
    <script type="text/javascript" src="/javascript.js"> </script>
    <title id="IDtitle"> mutford.net </title>

 <style type="text/css">

  input { width: 400px; }
  input.button { width: auto; }

 </style>

<?php  

  require("generic-form-modifiables.php");  

?>




</head>
<body>

<div class="whole" id="whole">

<div class="mainheader"> introduction </div>

<p>
This following form is generated by a PHP array of questions.  It will automatically build the list of questions and input fields.  Once done, the "Generate" button will process the questions and the fields into a finished printer-friendly version of the document, as well as generic a text document with similar layout.
</p>

<form id="generic-form" action="generic-form-processor.php" method="post">

<?php 

for ( $counter = 1; $counter <= $counterMax ; $counter++ )
 {

    echo '#' . $counter . ': <span id="question-' . $counter . '"> ' . $questions[$counter] . ' </span>';
    echo '<input id="answer-'. $counter  .'" name="answer-' . $counter . '" type="text" />';
    echo '<br />';

 } // for $counter

?>


<input type="submit" class="button" value="Generate Printer-Friendly Copy" /> <br />


</form>


</div>

</body>
</html>
generic-form-processor.php

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

    <link type="text/css" rel="stylesheet" href="/styles.css" />
    <script type="text/javascript" src="/javascript.js"> </script>
    <title id="IDtitle"> mutford.net </title>

 <style type="text/css">

  input { width: 400px; }
  input.button { width: auto; }

 </style>

<?php  

  require("generic-form-modifiables.php");  

?>




</head>
<body>

<div class="whole" id="whole">

<div class="mainheader"> processed information </div>


<?php 

  $ioFile = fopen( $outputFilename, 'a' ) or die( "Can't open file " . $outputFilename );
  // 'a' for APPEND, 'w' for WRITE, 'r' for READ, use unlink( ) to DELETE

  for ( $counter = 1; $counter <= $counterMax ; $counter++ )
   {

      // ***** QUESTION *******************************************************
      $writeThis = '#' . $counter . '
' . '### ' . $questions[$counter] . ' ### 
'; // newline hander

      fwrite( $ioFile, $writeThis );

      echo '<p><b>#' . $counter . ' ' . $questions[$counter] . ':</b>
'; // newline handler

      // ***** ANSWER *********************************************************
      $arrayKey = 'answer-' . $counter;

      $writeThis = $_POST[$arrayKey] . '

'; // newline handler

      fwrite( $ioFile, $writeThis );

      echo $_POST[$arrayKey];

      // ***** NEXT ITEM ******************************************************
      echo '</p>
'; // newline handler

   } // for $counter

   echo '<p> <a href="generic-form-interface.php">Click here to return to DATA INTERFACE for NEXT RECORD / BLANK FIELDS</a> </p>
'; // newline handler

   fwrite( $ioFile, $returnText );
   fclose( $ioFile );

?>





</div>

</body>
</html>
generic-form-output.php

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

Note: This file is blank at first. This is the file to which a text output is sent. Each submission through the form will APPEND this file.

generic-form-README.php

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

Legal terms: To use this set of generic form files, please indicate the primary source of the files 
using appropriate URIs (which necessarily include mutford.net as the root host). Please also indicate 
the primary author as Jason Mutford, but attributing any modifications to the appropriate modifying 
author(s). Likewise, the DOCUMENTATION FILE ought to be updated to include any citations for both 
original author and adaptation author. Any other use constitutes plagerism.

All primary unadulterated files written 3-4 May 2009, Jason Mutford, mutford.net, ©2009-2084



**** DEVELOPMENT NOTES *************************************************************************************************

generic-forms.php GAMEPLAN

1 file which includes the modifiables "generic-form-modifiables.php"
  Here, the maintainer will enter the QUESTIONS into an ARRAY and will also enter the SAVE FILE NAME
  This file will be "require( )"d by main interface.
  Hopefully, this will also eliminate the problems of editing away the primary structures below.

1 file which is the user interface "generic-form-interface.php"
  This "require( )"s the modifiables for generating the form itself
  The ACTION will move INPUT values to the GENERATED FILE

1 file which is the web version of the generated file "generic-form-processed.php"
  This "require( )"s the modifiables for generating the QUESTIONS
  The ANSWERS will be acquired through the POST method.
  This is ALSO the file the builds the next-listed SAVE FILE

1 file which is the save file "generic-form-output.php"
  APPENDED from PREVIOUS VALUES


PROGRESS:

  DONE - saved "generic-form-modifiables.php"
  DONE - saved the original "generic-forms.php" AS "generic-form-interface.php" with require("**-modifiables.php") in place
  TEST SUCCESSFUL "generic-form-interface.php"

  TRYING TO BUILD "generic-form-processor.php"
  BUILT "generic-form-processor.php" re: output page.
  TEST SUCCESSFUL on SCREEN OUTPUT "generic-form-processed.php"

  TRYING TO BUILD "generic-form-processor.php" for passing info to "generic-form-output.php"
  TEST SUCCESSFUL on FIRST FILE OUTPUT "generic-form-output.php"

  DONE - saved all files, TEST SUCCESSFUL IN FULL

// end PRIMARY AUTHOR NOTES ************************************************************************************************


styles.css

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

This stylesheet probably includes much more than needed to run the generic forms. Selectors known to not be used have been pre-deleted herein.

body
 {
   background-image: url(images/body-background.png);
   background-repeat: repeat-y;
   font-family: Tahoma, Verdana, sans-serif;
   font-size: 11px;
 }

.button
 {
   color: navy;
   font-family: Tahoma, Verdana, sans-serif;
   font-size: 9px;
   font-weight: bold;
   margin: 0px -2px;
   padding: 0px;
 }

input
 {
   color: #003366;
 }

.main
 {
   position: absolute;
     left: 140px;
     top: 42px;
   text-align: justify;
   width: 523px;
 }

.mainheader
 {
   background-color: #6699ff;
   border-color: #003366;
   border-style: solid;
   border-width: 1px 0px;
   color: #003366;
   font-size: 13px;
   margin: 2px 0px 1px 0px;
   padding: 1px 3px;
 }

.menu
 {
   background-color: #ddeeff;
   padding: 0px 2px;
   position: absolute;
     left: 8px;
     top: 57px;
   width: 121px;
 }

.menuheader
 {
   background-color: #6699ff;
   border-color: #003366;
   border-style: solid;
   border-width: 1px 0px;
   color: #003366;
   margin: 2px 0px 1px 0px;
   padding: 1px 3px;
 }

p
 {
   margin: 8px 0px;
 }

.pageheader
 {
   background-color: #6699ff;
   border-color: #003366;
   border-style: solid;
   border-width: 2px 0px;
   color: #003366;
   font-family: Arial, Tahoma, Verdana, sans-serif;
   font-size: 18px;
   margin: 0px 0px -13px 0px;
   padding: 1px 3px;
   spacing: 0px;
   width: 649px;
 }

.pageheaderdate
 {
   background-color: #6699ff;
   border-color: #003366;
   border-style: solid;
   border-width: 0px 2px 2px 0px;
   color: #003366;
   font-family: Verdana, "Courier New", monospace;
   font-size: 9px;
   margin: 0px 0px 5px 0px;
   padding: 1px 3px;
   width: 117px;
   spacing: 0px;
 }


.whole
 {
   position: absolute;
     left: 20px;
     top: 10px;
   text-align: justify;
   width: 613px;
 }


javascript.js

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

This javascript function library file probably includes much more than needed to run the generic forms. Functions known to not be used have been pre-deleted herein.

function ajax( filename, location )
  {
    var pageRequest = false;
    if ( window.XMLHttpRequest ) 
      { pageRequest = new XMLHttpRequest( ); }
    else if ( window.ActiveXObject ) 
      { pageRequest = new ActiveXObject('Microsoft.XMLHTTP'); }
    else return false;

    pageRequest.onreadystatechange = function( )
      { element( location ).innerHTML = pageRequest.responseText; } 

    pageRequest.open('GET',filename,true);
    pageRequest.send(null);
  }



function element ( passedValue )
  {  return document.getElementById( passedValue );  }



function headerTitle ( passedValue )
  {
     returnValue = '';
     returnValue += '<div class="pageHeader"> ';
     returnValue += passedValue + '<br />';
     returnValue += '<span class="fineprint"> ';
  }


function indent( measure, text )
  {
     document.write( '<div style="text-indent:' + measure + 'px;"> ' + text + ' </div>' );
     return;
  }


function toggle ( passedValue )
  {
    if ( element( passedValue ).style.display != 'none' )
      { element( passedValue ).style.display = 'none'; }
    else
      { element( passedValue ).style.display = 'inline'; }

  }

concluding comments

setup howto
generic-form-modifiables.php
generic-form-interface.php
generic-form-process.php
generic-form-ouptut.php
generic-form-README.php
styles.css
javascript.js
comments

Hopefully all works well for you. I am very pleased with my own creation here. Having a generic-form file set hanging around will make generating any forms in the future extremely easy, especially if there is a limited amount of time in which to set up the form. Hopefully, the output file has been set up for convenient adaption for MySQL databases as well (as I am not yet proficient by my standards in MySQL). Please feel free to send comments about these files to me; I'd be curious to hear how they are being used.