Location: PHPKode > projects > Tagging manager > version 1.02/includes/form.php
<?  
/**
 * WIP:: Forms - this is the basic file for the dynamic form's that will be introduced in version 1.5 (after summer 2006)
 *
 * @author hide@address.com
 * @version 1.0
 * @package Forms
 */


/**
 * The basics for a form-element
 */
class form_element
	{
		var			$name;
		var			$value;
		
		/**
 		* Form-element contstructor
 		*
 		* @param string $name Form element name
 		* @param string $value Form element value 		
 		*/
		function form_element ($name, $value)
		{
			$this->name		= $name;
			$this->value	= $value;
		}
	}

/**
 * Form element: text (gives <input type="text">)
 */	
class form_element_text extends form_element
	{
		var			$size;
		var			$maxlength;
		
		/**
 		* constructing the form element
 		*
 		* @param string $title Form element title
 		* @param string $name Form element name 
 		* @param string $value Form element value
 		* @param string $size Form element size
 		* @param string $maxlength Form element maxlenght
 		*/	
		function form_element_text ($title, $name, $value, $size, $maxlength)
		{
			$this->form_element		($title, $name, $value);
			$this->size				= $size;
			$this->maxlength		= $maxlength;
		}
		
		/**
 		* Returning the tag for the created form element text
 		*
 		* @returns string
 		*/		
		function getTag ()
		{
			return "<input type=\"text\" name=\"".$this->name."\" value=\"".$this->value."\" size=\"".$this->size."\" maxlength=\"".$this->maxlength."\" ><br>";
		}
	}

/**
 * Form element: combo (selectionboxes)
 */	
class form_element_combo extends form_element
	{
		var			$size;
		var			$values;
		var			$multiple;
		
		/**
 		* constructing the form element
 		*
 		* @param string $title Form element title
 		* @param string $name Form element name 
 		* @param string $value Form element value
 		* @param string $size Form element size
 		* @param string $maxlength Form element maxlenght
 		* @param string $values Form element values
 		* @param string $style Form element style
 		* @param string $multiple If element contains multiple values
 		*/	
		function form_element_combo ($title, $name, $value, $style, $size, $values, $multiple)
		{
			$this->form_element		($title, $name, $value, $style);
			$this->size				= $size;
			$this->values			= $values;
			$this->multiple			= $multiple;
		}
		
		/**
 		* Returning the tag for the created formcombe element text
 		*
 		* @returns string
 		*/	
		function getTag ()
		{
			$r = "";
			$r .= "<select name=\"".$this->name."\" class=\"".$this->style."\"".( $this->size != 0 ? "size=\"".$this->size."\"" : "").($this->multiple ? " multiple" : "").">";
			while (list ($value, $title) = each ($this->values))
				$r .= "<option value=\"$value\"".($value == $this->value ? " selected" : "").">$title</option>";
			$r .= "</select>";
			return $r;
		}
	}
	

/**
 * Form
 */	
class form
	{
		var			$elements;
		
		/**
 		* Form constructor
 		*/			
		function form ($screen)
		{
			$this->screen				= $screen;
		}
		
		/**
 		* addelement
 		*/	
		function addElement ($element)
		{
			$this->elements[] = $element;
		}
		
		/**
 		* getformelements: get's elements from database
 		*
 		* return string gives html output for form
 		*/	
		function getFormElements ($screen)
		{
			$r = "<table>";
			$form_elements = new iter("SELECT * FROM `tm_form` WHERE `screen` = $screen ORDER BY `sortorder` ASC ");

		while ($item = $form_elements->fetch()) {
    $r.="<tr><td>$item->title</td><td><input type=\"text\" name=\"".$item->name."\" onfocus=\"".$item->script."\" style=\"".$item->css."\" value=\"".$item->default_value."\">".$item->extra."</td></tr>";
    }
    $r.="</table>";
    return $r;
  }
			
	}
?>
Return current item: Tagging manager