Location: PHPKode > scripts > Form Builder > form-builder/examples/styling_form.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>
			<style type="text/css">
				.content {
					font: 13px Arial, Helvetica, sans-serif;
					color: #666;
				}

				.required {
					color: #990000;
				}

				.label {
					font-size: 1.1em;
					font-weight: bold;
					padding-top: 10px;
					color: #487EC1;
				}

				#styleFormExample {
					width: 250px;
				}

				/*Form element is inside td tags.*/
				#styleFormExample td {
					font: 13px Arial, Helvetica, sans-serif;
					color: #666;
				}

				/*The asterics for required fields are inside span tags.*/
				#styleFormExample span {
					color: #990000;
				}

				/*Element labels are inside div tags.*/
				#styleFormExample div {
					font-size: 1.1em;
					font-weight: bold;
					padding-top: 10px;
					color: #487EC1;
				}
			</style>
		</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>Styling Form</b> - This example demonstrates various ways to style your form and its elements. The two methods below are different but display the same result.</p>
			<?

			$form = new form();
			$form->setAttributes(array(
				"tableAttributes" => array("cellpadding" => 0, "width" => "250"),
				"tdAttributes" => array("class" => "content"),
				"requiredAttributes" => array("class" => "required"),
				"labelAttributes" => array("class" => "label")
			));

			$form->addHidden("cmd", "submit");
			$form->addTextbox("Textbox:", "field0", "", array("required" => 1));
			$form->addSelectbox("Selectbox:", "field1", "", array("" => "--Select an Option--", "option1" => "Option 1", "option2" => "Option 2"), array("required" => 1));
			$form->addCheckbox("Checkbox:", "field2", "", array("option1" => "Option 1"), array("required" => 1));

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

			//Render Form HTML
			$form->render();


			//Now let's look at another way of assigning the same styles.
			$form2 = new form();
			$form2->setAttributes(array(
				"tableAttributes" => array("cellpadding" => 0, "id" => "styleFormExample")
			));

			$form2->addHidden("cmd", "submit");
			$form2->addTextbox("Textbox:", "field0", "", array("required" => 1));
			$form2->addSelectbox("Selectbox:", "field1", "", array("" => "--Select an Option--", "option1" => "Option 1", "option2" => "Option 2"), array("required" => 1));
			$form2->addCheckbox("Checkbox:", "field2", "", array("option1" => "Option 1"), array("required" => 1));

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

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

Return current item: Form Builder