Location: PHPKode > scripts > Form and SQL generator > form-and-sql-generator/formtest.php
<?



# These are the values for the Selectbox
$Values = array(1 => "Da", 2 => "Ka", 3 => "La", 4 => "Za");


require("form.inc");

$TestForm = new Form;

#A bit unelegant, but necessary to append the date-info of the three selectboxes into one
# date again. 
if ($Submit)
	{
	 $Date = $Year.$Month.$Day;
	}


$TestForm -> StartForm("Testje", $PHP_SELF, $ShowVal);

$TestForm -> AddHTML("This is your basic textfield", "LabelText", "Label");
$TestForm -> TextField("TextTest", $TextTest);

$TestForm -> AddHTML("This is, well, your basic textarea", "LabelArea", "Label");
$TestForm -> TextArea("AreaTest", $AreaTest);

$TestForm -> AddHTML("Getting the picture yet?");
$TestForm -> SelectBox("SelectTest", $Values, $SelectTest);

$TestForm -> AddHTML("This actually does something... select it, and the values of the field will be
			shown after the submit", "LabelCheck", "Label");
$TestForm -> CheckBox("ShowVal", $ShowVal);

$TestForm -> AddHTML("Add a date ....", "LabelDate", "Label");
$TestForm -> DateField("Dates", $Date);

$TestForm -> AddHTML("And presto, your basic form. Now submit", "LabelSubmut", "Label");
$TestForm -> Submit("Submit", "Submit");

$TestForm -> EndForm();



if ($Submit)
	{
	 $TestForm -> SQLInsert("FooBarTableName");
	 ### Normally, I'd feed the line of SQL to my database class here
	 
	}
?>
<!-- Here we can start the HTML and print the PHP objects. I like to keep the main body of PHP 
	and the HTML page separated for those poor webdesigners =) -->
 
<body>
<script>
<?print $TestForm -> JavaScript?>
</script>

<style>
<!-- Put the CSS stuff here, e.g. for the AddHTML thingies, which are both labelled and id'd -->
</style>

<html>
<?print $TestForm -> RawHTML;

if ($Submit)
	{
	 print $TestForm -> SQL;
	}
?>
</html>
</body>
Return current item: Form and SQL generator