<?php
class Form
{
var $type;
var $name;
var $value;
var $size;
var $maxlength;
var $style;
var $label;
var $message;
var $form;
function __construct()
{
}
#-#############################################
# desc: generates form beginning
# param: name, action, method, enctype
# return: string
function form($name, $action, $method, $enctype=NULL)
{
$parameter = array();
$parameter['name'] = $name;
$parameter['id'] = $name;
$parameter['action'] = $action;
$parameter['method'] = $method;
$parameter['enctype'] = $enctype;
$this->form = '<form ';
// write parameter into form
foreach($parameter as $key => $value)
{
$this->form .= $key.'="'.$value.'" ';
}
$this->form .= '>';
return $this->form;
}
#-#############################################
# desc: generates a single textfield input
# param: type, name, value, disabled, readonly
# size, maxlength
# return: string
function textfield($type, $name, $tvalue=NULL, $disabled=NULL, $readonly=NULL, $width=NULL, $size=NULL, $maxlength=NULL, $clear=NULL)
{
unset($this->generated_input);
// add left border
#$this->generated_input = $this->border('textfieldbgleft.png');
// main field parameters
$parameter = array();
$parameter['type'] = $type;
$parameter['name'] = $name;
$parameter['value'] = $tvalue;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($readonly)) {
$parameter['readonly'] = $readonly;
}
#$parameter['width'] = $width;
$parameter['size'] = $size;
$parameter['maxlength'] = $maxlength;
$this->generated_input .= '<input id="'.$name.'" ';
if(!empty($width)) {
$this->generated_input .= 'style="width:'.$width.'" ';
}
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
// if $value is not empty:
// clear field on click
// change style
$change_color = 'this.style.color=\'#000\'';
if($clear == 'clear') {
$this->generated_input .= ' onClick="javascript:this.value=\'\'; '.$change_color.'"';
} else {
$this->generated_input .= ' onClick="javascript:'.$change_color.'"';
}
// add class
$this->generated_input .= ' class="input" />';
// add right border
#$this->generated_input .= $this->border('textfieldbgright.png', 'right');
return $this->generated_input;
}
#-#############################################
# desc: generates file input
# param: type, name, value, disabled, readonly
# size, maxlength
# return: string
function fileinput($name, $disabled=NULL, $readonly=NULL, $size=NULL, $maxlength=NULL)
{
unset($this->generated_input);
// main field parameters
$parameter = array();
$parameter['type'] = 'file';
$parameter['name'] = $name;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($readonly)) {
$parameter['readonly'] = $readonly;
}
$parameter['size'] = $size;
$parameter['maxlength'] = $maxlength;
$this->generated_input .= '<input id="'.$name.'" ';
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
// add class
$this->generated_input .= ' />';
return $this->generated_input;
}
#-#############################################
# desc: generates a textarea
# param: type, name, value, disabled, readonly
# size, maxlength
# return: string
function textarea($name, $rows, $cols, $tvalue=NULL, $disabled=NULL, $readonly=NULL, $size=NULL, $maxlength=NULL, $clear=NULL)
{
unset($this->generated_input);
// main field parameters
$parameter = array();
$parameter['name'] = $name;
$parameter['rows'] = $rows;
$parameter['cols'] = $cols;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($readonly)) {
$parameter['readonly'] = $readonly;
}
$parameter['size'] = $size;
$parameter['maxlength'] = $maxlength;
$this->generated_input .= '<textarea class="textarea" ';
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
// if $value is not empty:
// clear field on click
if($clear == 'clear') {
$this->generated_input .= ' onClick="javascript:this.value=\'\'"';
}
$tvalue = str_replace('<br />', '', $tvalue);
$this->generated_input .= '>'.$tvalue.'</textarea>';
return $this->generated_input;
}
#-#############################################
# desc: generates an hidden input
# param: name, value
# return: string
function hidden($name, $value)
{
$this->generated_input = '<input type="hidden" name="'.$name.'" value="'.$value.'" />';
return $this->generated_input;
}
#-#############################################
# desc: generates a select box
# param: name, (array) values
# return: string
function select($name, $values, $checked=NULL, $disabled=NULL, $readonly=NULL)
{
unset($this->generated_input);
// main field parameters
$parameter = array();
$parameter['name'] = $name;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($readonly)) {
$parameter['readonly'] = $readonly;
}
// main field
$this->generated_input .= '<select class="select" ';
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
$this->generated_input .= '>';
// add items
foreach($values as $key => $value)
{
if($key == $checked) {
$this->generated_input .= '<option value="'.$key.'" selected=selected>'.$value.'</option>';
} else {
$this->generated_input .= '<option value="'.$key.'">'.$value.'</option>';
}
}
$this->generated_input .= '</select>';
return $this->generated_input;
}
#-#############################################
# desc: generates a checkbox
# param: name, values
# return: string
function checkbox($name, $value, $checked=NULL, $disabled=NULL, $readonly=NULL)
{
unset($this->generated_input);
// main field parameters
$parameter = array();
$parameter['name'] = $name;
$parameter['value'] = $value;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($readonly)) {
$parameter['readonly'] = $readonly;
}
if(!empty($checked)) {
$parameter['checked'] = $checked;
}
$this->generated_input .= '<input id="'.$name.'" type="checkbox" ';
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
// add class
$this->generated_input .= ' class="checkbox" />';
return $this->generated_input;
}
#-#############################################
# desc: generates a button
# param: type, name, value
# return: string
function button($type, $name, $value, $disabled=NULL, $onclick=NULL)
{
unset($this->generated_input);
// main button parameters
$parameter = array();
$parameter['type'] = $type;
$parameter['name'] = $name;
$parameter['value'] = $value;
if(!empty($disabled)) {
$parameter['disabled'] = $disabled;
}
if(!empty($onclick)) {
$parameter['onclick'] = $onclick;
}
$this->generated_input .= '<input ';
// write parameter into input
foreach($parameter as $key => $value)
{
$this->generated_input .= $key.'="'.$value.'" ';
}
// add class
$this->generated_input .= ' class="button" />';
return $this->generated_input;
}
} //CLASS Form
###################################################################################################
?>