Location: PHPKode > scripts > StrudleForm > strudleform/StrudleForm.php
<?php
/*
	NAME: StrudleForm
	FILE: StrudleForm.php
	AUTHOR: Sean Meese
	WEBSITE: http://www.strudleman.com
	EMAIL: hide@address.com
	VERSION: 1.0 FINAL
	
	Strudleman's StrudleForm
	==========================
	
	Welcome to release v1.0 of Strudleman's StrudleForm Form Generator.  This is the 
	first public release.  Although I believe it to be completly bug free and option
	packed, I'm sure that there is plenty more that can be done with it.  If you find
	any bugs, have any suggestions, or comments on the script, PLEASE email me at 
	hide@address.com Also if you are confused or need assistance on anything 
	don't hesitate to email me at hide@address.com or go to 
	http://www.strudleman.com/strudlescripts
	
	Strudleman <hide@address.com>

	
*/
class FormX{

	//define vars
	var $size;
	var $max;
	var $rows;
	var $cols;
	var $method;
	var $name;
	var $enctype;
	var $css;
	var $color;
	var $background_color;
	var $border_bottom;
	var $border_left;
	var $border_right;
	var $border_top;
	var $font_size;
	var $font_family;
	
	
	function FormX()
	{
		$this->init();
	}
	
	function init()
	{
		/* Initialize default values for all variable */
		
		// Standard form values
		$this->size = 20;		// Set the size of text and password fields.
		$this->max = 40;		// Set max characters allowed in form field.
		
		$this->rows = 10;		// Set rows and column counts for the textarea form field.
		$this->cols = 40;	
		
		$this->method = 'post';		// Method your form uses, (i.e. post, get).
		$this->name = 'form';		// Specify the name of your form.  Usually not necessary.
		
		$this->enctype = "text/plain";	// "text/plain" - This should be good for most form submits.
						// "multipart/form-data" - Use this enctype if you're uploading somthing via form submit.
						// "application/x-www-form-urlencoded"; - This is for posting to a cgi-script, I believe.
		
		
		// CSS values
		$this->css = 'OFF';		// Set this to 'ON' to specify CSS values for form elements
						// If set to off, form elements will take their values from 
						// your global stylesheet, if you use one.
					
		// Use these only if $this->css is set to 'OFF'.
		// Variables are named after their CSS counterpart for usability.
		$this->color = '#000000';
		$this->background_color = '#FFFFFF';
		$this->border_bottom = '#AAAAAA 1px solid';
		$this->border_left = '#AAAAAA 1px solid';
		$this->border_right = '#AAAAAA 1px solid';
		$this->border_top = '#AAAAAA 1px solid';
		$this->font_size = '11px';
		$this->font_family = 'verdana, arial, sans-serif';
		
		
	}
	
	function setDefaults()
	{
		/* Resets all values to the default values */
		$this->init();
		$this->css = 'ON';	
	}
		
	function startForm($action)
	{
		/* Start the form.  Make sure the proper enctype is set, depending on 
		 * what you're using the form for. */
		$form="<form name='$this->name' enctype='$this->enctype' action='$action' method='$this->method'>\n";
		return $form;
	}
	
	function endForm()
	{
		/* Ends the form.  */
		$form = "</form>\n";
		return $form;
	}
	
	function drawCss()
	{
		/* This function is called by all the other functions that use CSS. */
		if(strtoupper($this->css)=='ON'){
			$form = "style='";
			$form .= "color: $this->color; ";
			$form .= "background-color: $this->background_color; ";
			$form .= "border-bottom: $this->border_bottom; ";
			$form .= "border-left: $this->border_left; ";
			$form .= "border-right: $this->border_right; ";
			$form .= "border-top: $this->border_top; ";
			$form .= "font-size: $this->font_size; ";
			$form .= "font-family: $this->font_family; ";
			$form .= "'";
		}else{
			$form = "";
		}
		return $form;
	}
	
	function drawText($name,$value="")
	{
		/* draws a text field */
		if($value!="") $value = "value=\"$value\"";
		$form="<input type='text' name='$name' $value maxlength='$this->max'  size='$this->size' ".$this->drawCss()." />\n";
		return $form;
	}
	
	function drawFile($name)
	{
		/* draws a file upload field */
		$form="<input type='file' name='$name' maxlength='$this->max' ".$this->drawCss()." />\n";
		return $form;
	}	
	
	function drawTextArea($name,$value=" ")
	{
		/* draws a textarea field */
		$form="<textarea name='$name' rows='$this->rows' cols='$this->cols' ".$this->drawCss()." >$value</textarea>\n";
		return $form;
	}
	
	function drawCheck($name,$value,$checked="")
	{
		/* draws a checkbox */
		if($value!="") $value = "value=\"$value\"";
		$form="<input type='checkbox' name='$name' value='$value' $checked />\n";
		return $form;
	}
	
	function drawRadio($name,$value,$checked="")
	{
		/* draws a radio button */
		$form="<input type='radio' name='$name' value='$value' $checked  />\n";
		return $form;
	}	
	
	function drawSubmit($value)
	{
		/* draws a submit button */
		$form="<input type='submit' value=\"$value\" ".$this->drawCss()." />\n";
		return $form;
	}
	
	function drawReset($value)
	{
		/* draws a reset button */
		$form="<input type='reset' value=\"$value\" ".$this->drawCss()." />\n";
		return $form;
	}
	
	function drawHidden($name,$value)
	{
		/* draws a hidden field */
		$form="<input type='hidden' name='$name' value=\"$value\" />\n";
		return $form;
	}
	
	function drawPassword($name,$value="")
	{
		/* draws a password field */
		if($value!="") $value = "value=\"$value\"";
		$form="<input type='password' name='$name' value=\"$value\" maxlength='$this->max' size='$this->size' ".$this->drawCss()." />\n";
		return $form;
	}
	
}


?>
Return current item: StrudleForm