Location: PHPKode > scripts > Form Builder > form-builder/examples/prefilling_form_elements.php
/*Include Form Class*/

	$cmd = "";

if($cmd == "submit")
	/*Handles Form Post*/

if($cmd == "")
			<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>Pre-filling Form Elements</b> - Each function for adding elements provides a parameter that will set the field's value; however, there is a convenient function built into this form class that will pre-fill all your fields at once.  Simply pass a hash array to the setReferenceValues where your keys are the field names.
			This method can be useful if you're pulling records from a database table, or doing error checking and want to pre-fill your fields from the $_GET sting.

			/*This simulates results returned from a db function or from the $_GET string. Notice that the array's keys match the form names.*/
			$ref = array(
				"field0" => "Value 0",	
				"field1" => "option1",	
				/*Pass an array of values to a checkbox if you want more than one checked.*/
				"field2" => array("option1", "option2"),	
				"field3" => date("F j, Y")

			$form = new form();
				"jqueryPath" => "../jquery",
				"returnUrl" => "prefilling_form_elements.php?cmd=",
				"tableAttributes" => array("width" => "300")

			/*Set Reference Values*/

			/*Add Fields*/
			$form->addHidden("cmd", "submit");
			$form->addTextbox("Textbox:", "field0");
			$form->addSelectbox("Selectbox:", "field1", "", array("" => "--Select an Option--", "option1" => "Option 1", "option2" => "Option 2"));
			$form->addCheckbox("Checkbox:", "field2", "", array("option1" => "Option 1", "option2" => "Option 2"));
			$form->addDate("Date:", "field3");
			<a href="../index.html">Back to Project Home Page</a>
Return current item: Form Builder