Location: PHPKode > scripts > Dynamic Elements Processor with PHP 5 > dynamic-elements-processor-with-php-5/examples.php
<?php
//error_reporting(E_ALL);

// just in case you don't use __autoload
require_once('classes/ProcessElements.class.php');
require_once('classes/ElementIterator.class.php');
require_once('classes/RecursiveArrayObject.class.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<meta name="generator" content="Adobe GoLive 6">
		<title>Dynamic Elements - Create them in no time</title>
		<link href="css/elements.css" rel="stylesheet" media="screen">
		<script type="text/javascript" src="scripts/elements.js"></script>
	</head>

	<body bgcolor="#ffffff">
		<p></p>
		<center>
		<?php
			$newelement = new ProcessElements();
			// spelling: "action","method","name","enctype","option"			
			$formdata = array(array("{$_SERVER['PHP_SELF']}",
										"POST","FormExample",
										"target=\"_self\"",
										"application/x-www-form-urlencoded",
										"OnSubmit=\"return validFormExample();\""));
			$newelement->createFormStart($formdata);
		?>
		<table width="50%" border="0" cellspacing="2" cellpadding="0">
			<caption><span class="title">Element Handler Examples</span></caption>
			<tr>
				<td valign="top" width="20%">Input</td>
				<td>
				<?php
					// default setting and spelling: 'name'						
					$newelement->createElement('input');
					// default setting and spelling: "'option','option','option'"
					// ATTENTION - if empty don't remove it! - JavaScript in last position
					$newelement->addOptions("tabindex='1',onclick='return validExample();'");
					// default setting and spelling: 'type','name','value'
					$newelement->appendElement('submit','SubmitButtonName','Send form');

					// example reset button
					$newelement->addOptions("tabindex='2',onclick='return ResetForm();'");
					$newelement->appendElement('reset','ResetButtonName','Reset');

					// example image button
					$newelement->addOptions("tabindex='3',src='images/imagebutton.gif'");
					$newelement->appendElement('image','ImageButtonName','Send form');
					echo "<br/>";
		
					// example file browser button
					$newelement->addOptions("tabindex='4'");
					$newelement->appendElement('file','fileName','Send form');
					echo "<br/>";

					// example text
					$newelement->addOptions("tabindex='5',onblur=\"return showNumbers('1','2');\"");
					$newelement->appendElement('text','textName',"");
					
					// example password
					$newelement->addOptions("tabindex='6'");
					$newelement->appendElement('password','passwordName','xxx');
					echo "<br/>";

					// example radio button
					$newelement->addOptions("tabindex='7',checked");
					$newelement->appendElement('radio','radioName','1');

					// example checkbox button
					$newelement->addOptions("tabindex='8',disabled,checked");
					$newelement->appendElement('checkbox','checkboxName','1');
					
					// example hidden field
					$newelement->addOptions("");
					$newelement->appendElement('hidden','hiddenName','1');
				?>
				</td>
			</tr>
			<tr>
				<td valign="top" width="20%">Select</td>
				<td>
				<?php	
					// example select element
					$shownumbers = null;
					$numberfill = range('1','9');
					foreach($numberfill as $val) { 
						$shownumbers .= "<option value='$val'>$val</option>"; }
					$newelement->createElement('select');
					$newelement->addOptions("tabindex='9',size='1'");
					$newelement->appendElement('','selectName',"{$shownumbers}");
					
					// example select multiple element
					$showyears = null;
					$yearfill = range('2007','2027');
					foreach($yearfill as $val) { 
						$showyears .= "<option value='$val'>$val</option>"; }
					$newelement->createElement('select');
					$newelement->addOptions("tabindex='10',size='3',multiple");
					$newelement->appendElement('','selectName',"{$showyears}");
  				?>
  				</td>
			</tr>
			<tr>
				<td valign="top" width="20%">Textarea</td>
				<td>
				<?php
					// example textarea element
					$newelement->createElement('textarea');
					$newelement->addOptions("tabindex='11',rows='4',cols='40'");
					$newelement->appendElement('','textareaName',"Hello you!");
				?>
  				</td>
			</tr>
			<tr>
				<td valign="top" width="20%">Keygen</td>
				<td>
				<?php
					// example keygen element
					$newelement->createElement('keygen');
					$newelement->addOptions("challenge='keygenstring'");
					$newelement->appendElement('','keygenName','');
  				?>keygen is not compatible with all browsers
  				</td>
			</tr>
			<tr>
				<td valign="top" width="20%">Span</td>
				<td><?php
					// example span element
					$newelement->createElement('span');
					$newelement->addOptions("id='spanId'");
					$newelement->appendElement('','SpanName',
												'Click send form button, to see content.');
  				?></td>
			</tr>
			<tr>
				<td valign="top" width="20%">Div</td>
				<td><?php
					// example div element
					$newelement->createElement('div');
					$newelement->addOptions("id='divId'");
					$newelement->appendElement('','DivName',
												'Click send form button to see content.');
  				?></td>
			</tr>
			<tr>
				<td valign="top" width="20%">Label</td>
				<td><?php
					// example label element
					$newelement->createElement('label');
					$newelement->addOptions("for='ID_textName_1CA6B87A88B7830'");
					$newelement->appendElement('','','LabelContent');
  				?></td>
			</tr>
			<tr>
				<td valign="top" width="20%">Table</td>
				<td><?php
					// example table element (caption not supported)
					$showtabs = null;
					$numbertab = range('A','D');
					foreach($numbertab as $val) { 
						$showtabs .= "<tr><td>$val</td><td>$val</td></tr>"; }
					$newelement->createElement('table');
					$newelement->addOptions("border='1',width='100',height='60',cellspacing='2',cellpadding='0'");
					$newelement->appendElement('','',"{$showtabs}");
  				?></td>
			</tr>
		</table>
		<?php
			$newelement->createFormEnd();
		?>
		</center>	
	</body>

</html>
Return current item: Dynamic Elements Processor with PHP 5