Login   Register  
PHP Classes
elePHPant
Icontem

File: class.formwriter.php4

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Matthias Richter  >  phpMyCoCo  >  class.formwriter.php4  >  Download  
File: class.formwriter.php4
Role: ???
Content type: text/plain
Description: mini xhtml formwriter used by the coming-up admin-tool
Class: phpMyCoCo
Author: By
Last change:
Date: 2001-05-06 06:24
Size: 3,227 bytes
 

Contents

Class file image Download
<?

/************************************************************
 * @author: 	Matthias Richter <matthias@vielfalt.de>
 * @version:	0.2 (xhtml / stable)
 * @date:	2001-05-06
 * @license: 	GPL
 * @changes:	0.2: 	Added xhtml-compliancy
 *			Code cleanups
 *
 * Everybody is tired of writing Forms and so am I. This
 * class is not feature-complete at all, but it keeps you
 * away from writing html-Forms over and over again.
 *
 * Output is formatted into a table of (configurable) width
 * and should be xhtml 1.0 compliant. Appearance of text can
 * be tweaked by editing the style class for .formtext {}
 *
 * Don't forget to use this class for writing html-Forms
 * only in a normalized Form (which means putting error
 * checking and form generation into one file, so that the
 * generated form is presented to the user until correctly
 * filled out.)
 * FIXME: add an english-language link here.
 *
 * See http://www.koehntopp.de/php/faq-code.html#code-5 for
 * examples on good form-processing
 *
 * FIXME: add a class which allows for automatic input
 * checking
 *
 * FIXME: support all Form-Elements from XHTML 1.0
 ************************************************************/

class HtmlFormWriter
{
  function startForm ($formmname,$formethod,$formaction,$tablewidth)
  {
    echo  "\n\n<form action=\"$formaction\" method=\"$formethod\" ".
	  "name=\"$formname\"><table width=\"$tablewidth\">\n";
  }

  function addInput ($elementname,$prependtext,$elementvalue)
  {
    echo  "<tr><td align=\"right\"><p class=\"formtext\">$prependtext".
	  "</p></td><td><input type=\"text\" name=\"$elementname\" ".
	  "value=\"$elementvalue\" /></td></tr>\n";
  }

  function addLine ($title,$text)
  {
    echo  "<tr><td align=\"right\"><p class=\"formtext\">$title</p></td>".
	  "<td><p>$text</p></td></tr>\n";
  }

  function addHidden ($elementname,$elementvalue)
  {
    echo  "<input type=\"hidden\" name=\"$elementname\"".
	  " value=\"$elementvalue\" />\n"; 
  }

  function addCheckbox ($elementname,$elementtext,$elementstate)
  {
    if($elementstate==true) {
      $element = "<input type=\"checkbox\" name=\"$elementname\" checked />";
    } else {
      $element = "<input type=\"checkbox\" name=\"$elementname\" />";
    }
    echo  "<tr><td align=\"right\">$element</td><td><p class=\"formtext\">".
	  "$elementtext</p></td></tr>\n";
  }
  
  function addPassword ($elementname,$prependtext,$elementvalue)
  {
    echo  "<tr><td align=\"right\"><p>$prependtext</p></td>".
	  "<td><input type=\"password\" name=\"$elementname\"".
	  " value=\"$elementvalue\" /></td></tr>\n"; 
  }

  function addTextArea ($elementname,$prependtext,$elementvalue)  
  {
    echo  "<tr><td align=\"right\"><p class=\"formtext\">$prependtext".
	  "</p></td><td><textarea rows=\"10\" cols=\"50\" name=".
	  "\"$elementname\">$elementvalue</textarea></td></tr>\n<br>";
  }
  
  function addSubmit ($prependtext,$buttontext)
  {
    echo  "<tr><td><p class=\"formtext\">$prependtext</p></td><td><input".
	  " type=\"submit\" value=\"$buttontext\" /></td></tr>\n";
  }

  function endForm()
  {
    echo "</table></form>\n";
  }

}
?>