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

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>Adding Form Elements</b> - This example demonstrates all supported form element types and the various ways to attach them to a form.  There is one form element type 
			that is not included - latlng - as it requires a Google Map API Key specific to your domain.  An example of this field is commented out in this script's php source.</p>
			<?

			//Create form object instance and apply basic parameters
			$form = new form();
			$form->setAttributes(array(
				"jqueryPath" => "../jquery",
				"tableAttributes" => array("width" => "300")
				//"googleMapsAPIKey" => "ABQIAAAAGkAXtILEQ0HGorBDDXXyDxQfYTdFkbZjcQSPkKwdAKL2zU_aExSMelXtVbKbqmiUHq3bbCg5YhjPJA"
			));

			//Add Multiple Elements With addElements Function
			//----------------------------------------------------------------------------------
			//function addElements($arr)
			$form->addElements(array(
				array("name" => "field0", "type" => "hidden", "name" => "cmd", "value" => "submit"),
				array("label" => "Textbox:", "name" => "field1"),
				array("label" => "Select Box:", "name" => "field2", "type" => "select", "options" => array(
					"option0" => "Option 0",	
					"option1" => "Option 1"	
				)),
				array("label" => "Radio Buttons:", "name" => "field3", "type" => "radio", "options" => array(
					"option0" => "Option 0",	
					"option1" => "Option 1"	
				)),
			));
			//----------------------------------------------------------------------------------

			//Add Elements Individually With addElement Function
			//----------------------------------------------------------------------------------
			//function addElement($label, $name, $type="", $value="", $additionalParams="")
			$form->addElement("File Dialog:", "field4", "file");
			$form->addElement("jQuery Date:", "field5", "date");
			//----------------------------------------------------------------------------------

			//Add Elements Individually With Custom Add Functions
			//----------------------------------------------------------------------------------
			//function addHidden($name, $value="", $additionalParams="")
			//function addTextbox($label, $name, $value="", $additionalParams="")
			//function addSelectbox($label, $name, $value="" $options="", $additionalParams="")
			//function addRadio($label, $name, $value="" $options="", $additionalParams="")
			//function addCheckbox($label, $name, $value="" $options="", $additionalParams="")
			//function addState($label, $name, $value="", $additionalParams="")
			//function addCountry($label, $name, $value="", $additionalParams="")
			//function addYesNo($label, $name, $value="", $additionalParams="")
			//function addTrueFalse($label, $name, $value="", $additionalParams="")
			//function addTextarea($label, $name, $value="", $additionalParams="")
			//function addPassword($label, $name, $value="", $additionalParams="")
			//function addFile($label, $name, $value="", $additionalParams="")
			//function addDate($label, $name, $value="", $additionalParams="")
			//function addSort($label, $name, $options="", $additionalParams="")
			//function addLatLng($label, $name, value="", $additionalParams="")

			$form->addCheckbox("Checkbox:", "field6", "", array("option1" => "Option 1", "option2" => "Option 2"));
			$form->addState("State:", "field7");
			$form->addCountry("Country:", "field8");
			$form->addYesNo("Yes/No:", "field9");
			$form->addTrueFalse("True/False:", "field10");
			$form->addPassword("Password:", "field11");
			$form->addTextarea("Textarea:", "field12");
			$form->addSort("jQuery Sort:", "field13", array("option1" => "Option 1", "option2" => "Option 2", "option3" => "Option 3"));
			//$form->addLatLng("Latitude/Longitude:", "field14");
			//----------------------------------------------------------------------------------

			//Add Submit Button
			$form->addButton();

			//Render Form HTML
			$form->render();
			?>
			<a href="../index.html">Back to Project Home Page</a>
		</body>
	</html>
	<?
}
?>

Return current item: Form Builder