Location: PHPKode > projects > ArasPhp Framework > ArasPhp-0.03/core/helpers/Form.php
<?php

/**
 * Helper -> form
 * Helps creating form elements
 */
 
 class Form {
 
 	/**
 	 * Displays 3 drop down menus for submiting a date
 	 */
 	 
 	 public function dateForm($varname, $past = true)
 	 {
 	 	// Config
 	 	$days = 31;
 	 	$months = 12;
 	 	
 	 	if($past == true)
 	 	{
 	 		$firstYear = date("Y") - 100;
 	 	} else {
 	 		$firstYear = date("Y") - 50;
 	 	}
 	 	$years = $firstYear + 100;
 	 	?>
 	 	
 	 	<select name="<?= $varname ?>[year]">
	 	 	<?php
	 	 		for($it = $firstYear; $it <= $years; $it++)
	 	 		{
	 	 			echo "<option value='$it'>$it</option>";
	 	 		}
	 	 	?>
 	 	</select>
 	 	-
 	 	<select name="<?= $varname ?>[month]">
	 	 	<?php
	 	 		for($it = 1; $it <= $months; $it++)
	 	 		{
	 	 			echo "<option value='$it'>$it</option>";
	 	 		}
	 	 	?>
 	 	</select>
 	 	-
 	 	<select name="<?= $varname ?>[day]">
	 	 	<?php
	 	 		for($it = 1; $it <= $days; $it++)
	 	 		{
	 	 			echo "<option value='$it'>$it</option>";
	 	 		}
	 	 	?>
 	 	</select>
 	 	
 	 	<?php
 	 }
 	 
 	 /**
 	 * Creates a dropdown menu with all options from a category-similar table
 	 * Uses id, model passed and content-field passed
 	 * @param string model to create menu
 	 * @param string field to display
 	 * @param string name of the form variable to create
 	 */
 	 public function createSelectMenu($model, $field, $selectName)
 	 {
 	 	$query = new Query();
 	 	$elements = $query->getAll($model);
 	 	
 	 	if($elements != NULL)
 	 	{
 	 		sort($elements);
 	 		echo "<select name='$selectName'>";
 	 		
 	 			foreach($elements as $element)
 	 			{
 	 				echo "<option value='". $element->id ."'>". $element->$field ."</option>";
 	 			}
 	 	
 	 		echo "</select>";
 	 		
 	 	} else {
 	 	
 	 		echo "No elements in database";
 	 	}
 	 	unset($query);
 	 }
 	 
	
}


?>
Return current item: ArasPhp Framework