Location: PHPKode > scripts > Form Builder > form-builder/examples/changing_form_structure.php
<?
/*Include Form Class*/
include("../class.form.php");
session_start();

if(!isset($cmd))
	$cmd = "";

if($cmd == "submit")
{
	/*Handles Form Post*/
	echo("<pre>");
	print_r($_POST);
	echo("</pre>");
	exit();
}

if($cmd == "")
{
	?>
	<html>
		<head></head>
		<body>
			<h2 style="text-align: center; margin: 0; padding: 0;">Form Builder Class - Examples</h2>
			<h5 style="text-align: center; margin: 0; padding: 0;"><span style="padding-right: 10px;">Author: Andrew Porterfield</span><span style="padding-right: 10px;">Released: April 24, 2009</span><span>Version: 0.4.0<span></h5>
			<a href="../index.html">Back to Project Home Page</a>
			<p><b>Changing Form Structure</b> - By default, this form class will render one form element per line in a table structure.  There are several ways you can override this.  The first is to use the "map" parameter to define how many elements to display per line. 
			In the first example form below, I have passed an array containing (2, 3, 2, 3) which renders 2 fields on the first line, 3 on the second, etc. The second method uses a function elementsToString, which returns all attached elements in string form.
			Also used is the clearElements function which clear all elements attached to the form.  The second form below utilizes this method to format fields into three columns.
			</p>
			<?

			/*This example uses the map parameter to format the form elements.*/
			$form = new form();
			$form->setAttributes(array(
				"returnUrl" => "changing_form_structure.php?cmd=",
				"map" => array(2, 3, 2, 3),
				"tableAttributes" => array("width" => "500")
			));

			/*Add Fields*/
			$form->addHidden("cmd", "submit");
			$form->addTextbox("Field 0", "field0");
			$form->addTextbox("Field 1", "field1");
			$form->addTextbox("Field 2", "field2");
			$form->addTextbox("Field 3", "field3");
			$form->addTextbox("Field 4", "field4");
			$form->addTextbox("Field 5", "field5");
			$form->addTextbox("Field 6", "field6");
			$form->addTextbox("Field 7", "field7");
			$form->addTextbox("Field 8", "field8");
			$form->addTextbox("Field 9", "field9");

			$form->addButton();
			$form->render();

			/*This example uses the elementsToString function to format the form elements.*/
			$form = new form();
			?>
			<form action="changing_form_structure.php" method="post">
			<input type="hidden" name="cmd" value="submit">
			<table cellpadding="0" cellspacing="0" border="0" width="500">
				<tr>
					<td align="left" valign="top" width="33%">
					<?
					$form->addTextbox("Field 0", "field0");
					$form->addTextbox("Field 1", "field1");
					$form->addTextbox("Field 2", "field2");
					echo($form->elementsToString());
					$form->clearElements();
					?>
					</td>
					<td align="left" valign="top" width="33%">
					<?
					$form->addTextbox("Field 3", "field3");
					$form->addTextbox("Field 4", "field4");
					$form->addTextbox("Field 5", "field5");
					echo($form->elementsToString());
					$form->clearElements();
					?>
					</td>
					<td align="left" valign="top">
					<?
					$form->addTextbox("Field 6", "field6");
					$form->addTextbox("Field 7", "field7");
					$form->addTextbox("Field 8", "field8");
					echo($form->elementsToString());
					$form->clearElements();
					?>
					</td>
				</tr>
				<tr><td align="right" valign="top" colspan="3">
					<input type="submit" value="Submit">
				</td></tr>
			</table>	
			</form>
			<a href="../index.html">Back to Project Home Page</a>
		</body>
	</html>	
	<?
}
?>
Return current item: Form Builder