/*
This class will provide you a way to automate the creation
of HTML form
*/
class formHTML //Class to generate HTML form with any king of INPUT, SELECT or TEXTAREA
{
var $numFields; //Number of elements in the html form
var $Method; //Method to send the data
var $Action; //Script that will process the data
var $EncType; //Type of Data in form
var $Name; //form Name
var $Text; //Array of values for Input field types (SUBMIT|RESET|RADIO|CHECKBOX|FILE|TEXT|HIDDEN|IMAGE|BUTTON|PASSWORD)
var $TextArea; //Array of values for Text Area Input type
var $List; //Array of values for Select Input type
var $BrOn; //Just if you want to add a
after each field
var $FocusField; //Name of the field that you want to be selected before page load
var $FieldName; //Array store each field name
var $FieldType; //Array store each Type of each field
var $OnSubmit; //For JavaScript added 09/05/2005
function formHTML()
{
global $_SERVER; //Needed for access the $_SERVER['PHP_SELF'] varaible
$this->numFields=0; //Setting to 0
$this->Method="POST"; //Setting by default to POST
$this->Action=$_SERVER['PHP_SELF']; //Setting by default to $_SERVER['PHP_SELF']
$this->EncType=""; //Setting by default to empty
$this->Name="form" . uniqid(time());//Setting a defualt Unique form name
$this->BrOn=true; //Setting by default to true
$this->Text['MaxSize']=10; //Setting by default to 10
$this->Text['Size']=10; //Setting by default to 10
}
function open()
{ //Just print the form tag
echo "\r";
if (isset($this->FocusField))
{
echo "";
}
echo "\r";//Just to keep the html code in order see the page generated code
}
function FindType($Field)
{ //Find the type of any form field
$encontrado ="";
for ($x=0;$x<$this->numFields;$x++)
{
if (strtoupper($Field)==strtoupper($this->FieldName[$x]))
{
$encontrado = $this->FieldType[$x];
break;
}
}
return $encontrado;
}
function AddField()
//General Porpuse form input
//supported types SUBMIT RESET RADIO CHECKBOX FILE TEXT HIDDEN IMAGE BUTTON PASSWORD
{
if (isset($this->Text['Type']))
{
if (!((strtoupper($this->Text['Type'])!="SUBMIT") &&
(strtoupper($this->Text['Type'])!="RESET") &&
(strtoupper($this->Text['Type'])!="RADIO") &&
(strtoupper($this->Text['Type'])!="CHECKBOX") &&
(strtoupper($this->Text['Type'])!="FILE") &&
(strtoupper($this->Text['Type'])!="TEXT") &&
(strtoupper($this->Text['Type'])!="HIDDEN") &&
(strtoupper($this->Text['Type'])!="IMAGE") &&
(strtoupper($this->Text['Type'])!="BUTTON") &&
(strtoupper($this->Text['Type'])!="PASSWORD")))
{ // begin if block
echo "\t";
if (isset($this->Text['Label']))
{
echo $this->Text['Label'] . " ";
}
echo "Text['Type'] . "\" ";
if (isset($this->Text['Style']))
{
echo " class=\"" . $this->Text['Style'] . "\" ";
}
if (!isset($this->Text['Name']))
// auto asign name
// if name is null
{
$this->Text['Name'] = "field" . uniqid(time());
}
echo " name=\"" . $this->Text['Name'] . "\" ";
if (!isset($this->Text['Value']))
{
switch ($this->Text['Type'])
{
case "SUBMIT": $this->Text['Value']="SUBMIT";
break;
case "RESET" : $this->Text['Value']="CANCEL";
break;
default : $this->Text['Value']="";
}
}
echo " value=\"" . $this->Text['Value'] . "\" ";
if (isset($this->Text['Checked']) and $this->Text['Checked']==true)
{
echo " Checked ";
}
if (isset($this->Text['Disable']) and $this->Text['Disable']==true)
{
echo " disable=\"true\" ";
}
if (isset($this->Text['JavaEvent']) && isset($this->Text['Java']))
{
echo $this->Text['JavaEvent'] . "=\"" . $this->Text['Java'] . "\" ";
}
if (isset($this->Text['Id']))
{
echo "Id=\"" . $this->Text['Id'] . "\" ";
}
if (isset($this->Text['Src']))
{
echo " src=\"" . $this->Text['Src'] . "\" ";
}
if (isset($this->Text['MaxSize']))
{
echo " maxlength=\"" . $this->Text['MaxSize'] . "\" ";
}
if (!isset($this->Text['Size'])) // default asign
{
echo " size=\"" . $this->Text['Size'] ."\"";
}
echo " >";
if ($this->BrOn) echo "
\r";
else echo "\r";
$this->FieldType[$this->numFields]=$this->Text['Type'];
$this->FieldName[$this->numFields]=$this->Text['Name'];
$this->numFields++;
}//end if type
}
unset($this->Text['Name']);
unset($this->Text['Type']);
unset($this->Text['Value']);
unset($this->Text['Style']);
unset($this->Text['Java']);
unset($this->Text['JavaEvent']);
unset($this->Text['Label']);
unset($this->Text['MaxSize']);
unset($this->Text['Size']);
unset($this->Text['Checked']);
unset($this->Text['Src']);
unset($this->Text['Disable']);
} //end function
function ListOpen()
{
echo "\t";
if (!isset($this->List['Name'])) // auto asign name
{
$this->List['Name'] = "field" . uniqid(time());
}
echo "\r";
if ($this->BrOn) echo "
\r";
else echo "\r";
unset($this->List['Default']);
} //end function
function AddList()
{
echo "\t";
if (!isset($this->List['Name'])) // auto asign name
{
$this->List['Name'] = "field" . uniqid(time());
}
echo "\r";
if ($this->BrOn) echo "
\r";
else echo "\r";
$this->FieldType[$this->numFields]="SELECT";
$this->FieldName[$this->numFields]=$this->List['Name'];
$this->numFields++;
unset($this->List['Name']);
unset($this->List['Multiple']);
unset($this->List['Default']);
unset($this->List['Style']);
unset($this->List['Java']);
unset($this->List['JavaEvent']);
unset($this->List['Label']);
unset($this->List['MaxSize']);
unset($this->List['Size']);
unset($this->List['Checked']);
unset($this->List['Src']);
unset($this->List['Id']);
} //end function
function AddTextArea()
{
echo "\t";
//
if (!isset($this->TextArea['Name'])) // auto asign name
{
$this->TextArea['Name'] = "field" . uniqid(time());
}
echo "\r";
if ($this->BrOn) echo "
\r";
else echo "\r";
$this->FieldType[$this->numFields]="TEXTAREA";
$this->FieldName[$this->numFields]=$this->TextArea['Name'];
$this->numFields++;
unset($this->TextArea['Name']);
unset($this->TextArea['Type']);
unset($this->TextArea['Value']);
unset($this->TextArea['Style']);
unset($this->TextArea['Java']);
unset($this->TextArea['JavaEvent']);
unset($this->TextArea['Label']);
unset($this->TextArea['MaxSize']);
unset($this->TextArea['Size']);
unset($this->TextArea['Checked']);
unset($this->TextArea['Src']);
unset($this->TextArea['Rows']);
unset($this->TextArea['Cols']);
unset($this->TextArea['Wrap']);
unset($this->TextArea['Id']);
} //end function
} // end Class
// and example
$forma = new formHTML;
$forma->Name="mainForma";
$forma->Method="POST";
$forma->Action=$ACCION;
$forma->OnSubmit=$onsubmit;
$forma->open();
$forma->Text['Type']="HIDDEN";
$forma->Text['Name']="modulo";
$forma->Text['Value']=$modulo;
$forma->AddField();
$forma->Text['Type']="HIDDEN";
$forma->Text['Name']="submodulo";
$forma->Text['Value']=$submodulo;
$forma->AddField();
$forma->close();
?>