Hi, I've just written the class below to simply automate form building, but this is my first real attempt at using PHP Classes and for some reason it's not showing anything. This is the code I've giving on the main page, and below that is the class file. If anyone can point me in the right direction that would be great.
I'm using PHP Version 5.1.4 on Apache2 showing EVERY warning, if that helps.
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<?php
/*require('includes/db.class.php');*/
require('includes/formfactory.class.php');
$title = "Add image to image database";
/* Removing this code for the sake of viewing
$db = new database;
$db->connect_db();*/
$form = new formfactory;
$form->textBox("Test1:", "test_1", "Chicken");
$form->textBox("Test2:", "test_2", "Chicken Soup");
$form->textBox("Test3:", "test_3", "Chicken Poot");
$form->textBox("Test4:", "test_4", "Poot poot...");
$form->submitButton("Submit", "submit", "Send it all!");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Adobe GoLive" />
<title>imageFlasher</title>
<link href="css/basic.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div id="wrapper">
<div id="options">
<h1>Gallery</h1>
</div>
<div id="body">
<p><? echo $form->constructForm; ?></p>
</div>
<div id="footer">
<p></p>
</div>
</div>
</body>
</html>
formfactory.class.php
<?php
class formfactory
{
var $formElement = array();
var $allTaggedUp;
var $constructForm;
function layoutFormField($label, $element)
{
$allTaggedUp = " <div id='label'>".$label."</div>\n";
$allTaggedUp .= " <div id='input'>\n";
$allTaggedUp .= " ".$element."\n";
$allTaggedUp .= " </div>\n";
return $allTaggedUp;
}
function textBox($label, $name, $value)
{
$element->label = $label;
$element->form = "<input type='text' name='".$name."' value='".$value."' />";
$this->formElement[] = $element;
}
function submitButton($label, $name, $value)
{
$element->label = $label;
$element->form = "<input type='submit' name='".$name."' value='".$value."' />";
$this->formElement[] = $element;
}
function buildForm($location, $method)
{
echo "<form action='".$location."' method='".$method."'>\n";
echo "<div id='form'>\n";
foreach($this->formElement as $element)
{
echo layoutFormField($element->label, $element->form);
}
echo "</div>\n</form>\n";
}
}
?>
Thanks in advance!