This class can be used to compose and output HTML forms.
It can generate HTML form different types of form inputs and other types of HTML elements given parameters that defines details of each type of element.
The generated HTML is returned as a string that can be assembled with other parts of the final HTML page.
autohtmlforms.php
<?php
class autohtmlforms{
public function TextFieldEng($id,$class,$textfieldname,$type,$value,$size,$maxlegth)
{
$textfield_eng = "$textfieldname:<input name='$textfieldname' type='$type' id='$id' class='$class' value='$value' size='$size' maxlength='$maxlegth' />";
return $textfield_eng;
}
public function TextAreaEng($id,$class,$TextAreaName,$Columns,$Rows)
{
$textarea_eng = "$TextAreaName:<text area name='$TextAreaName' id='$id' class='$class' cols='$Columns' rows='$Rows'></text area>";
return $textarea_eng;
}
public function ButtonEng($id,$class,$button_name,$button_type,$button_value)
{
if ($button_type!="submit")
{
$button_eng = "<input name='$button_name' type='$button_type' id='$id class='$class' value='$button_value'>";
return $button_eng;
}
else
$button_eng = "<input name='$button_name' type='$button_type' id='$id class='$class' value='$button_value'></form>";
return $button_eng;
}
public function Checkbuttoneng($id,$class,$CheckButtonName,$TypeCheckButton,$ValueCheckButton,$InitValueCheckButton)
{
if($InitValueCheckButton!=""){
$Checkbutton_eng = "<input name='$CheckButtonName' type='$TypeCheckButton' id='$id' class='$class' value='$ValueCheckButton' checked='checked'>";
return $Checkbutton_eng;
}
else
{
$Checkbutton_eng = "<input name='$CheckButtonName' type='$TypeCheckButton' id='$id' class='$class' value='$ValueCheckButton'>";
return $Checkbutton_eng;
}
}
public function Radiobuttoneng($id,$class,$RadioButtonName,$TypeRadioButton,$ValueRadioButton,$InitValueRadioButton)
{
if($InitValueRadioButton!=""){
$Radiobutton_eng = "<input name='$RadioButtonName' type='$TypeRadioButton' id='$id' class='$class' value='$ValueRadioButton' checked>";
return $Radiobutton_eng;
}
else
{
$Radiobutton_eng = "<input name='$RadioButtonName' type='$TypeRadioButton' id='$id class='$class' value='$ValueRadioButton'>";
return $Radiobutton_eng;
}
}
public function FormEng($id,$class,$action,$method,$encoding,$FormName,$target)
{
$Form_eng = "<form action='$action' method='$method' enctype='$encoding' id='$id' class='$class' name='$FormName' target='$target'>";
return $Form_eng;
}
public function nlabeleng($id,$class,$msg)
{
$nlabel_eng = " <label id='$id' class='$class'>$msg</label>";
return $nlabel_eng;
}
public function Hr($id,$class)
{
$H_r = "<hr id='$id' class='$class'\>";
return $H_r;
}
public function Br($id,$class)
{
$B_r = "<br id='$id' class='$class'\>";
return $B_r;
}
public function endForm()
{
$enform = "</form>";
return $enform;
}
}
?>
examples.php
<?php
require_once("autohtmlforms.php");
$newtextf = new autohtmlforms(); //create textfield objet
$newbutton = new autohtmlforms();//create button objet
$newtextA = new autohtmlforms();//create textarea objet
$newcheckB = new autohtmlforms();//create checkbox objet
$newradioB = new autohtmlforms();//create radio objet
$newform= new autohtmlforms();//create form objet
//engine messages
$new_label = new autohtmlforms();
//engine <br> html tag
$newbr = new autohtmlforms();
$jump = $newtextf->Br();
//engine <hr> html tag
$newhr = new autohtmlforms();
$hr = $newhr->Hr();
// end form tag
$endform = new autohtmlforms();
/* Explane use*/
echo $newform->FormEng("examples.php","post","","form1","_self"); //"action url","method: get or post","encoding","form name","target"
echo $hr.$new_label->nlabeleng("Example of Textfield").$jump.$jump;
echo $newtextf->TextFieldEng("Nombre","text","","50","50"); //"name","type","value","size","maxlegth"
echo $newtextf->TextFieldEng("Apellido","text","","50","50"); //"name","type","value","size","maxlegth"
echo $hr.$new_label->nlabeleng("Example of Text Area").$jump.$jump;
echo $newtextA->TextAreaEng("Comentario","50","10"); //,"TextAreaName","columns","rows"
echo $hr.$new_label->nlabeleng("Example of Button").$jump.$jump;
echo $newbutton ->ButtonEng("submit","submit","Submit"); //,"ButtonName","Buttontype","buttonvalue"
echo $hr.$new_label->nlabeleng("Example of Check Button").$jump.$jump;
echo $newcheckB ->Checkbuttoneng("CheckButtonName","checkbox","ValueCheckButton","checked"); //"CheckButtonName","checkbox","ValueCheckButton","checked"
echo $newcheckB ->Checkbuttoneng("CheckButtonName","checkbox","ValueCheckButton",""); //"CheckButtonName","checkbox","ValueCheckButton","" <--- unchecked
echo $hr.$new_label->nlabeleng("Example of Radio Button").$jump.$jump;
echo $newradioB ->Radiobuttoneng("RadioButtonName","radio","ValueRadioButton","checked"); //"RadioButtonName","Radio","ValueRadioButton","checked"
echo $newradioB ->Radiobuttoneng("RadioButtonName","radio","ValueRadioButton",""); //"RadioButtonName","Radio","ValueRadioButton","" <--- unchecked
echo $endform->endForm(); //show </form> tag if you not closed the form with submit buttom
?>
<p>/* this example engine is*/</p>
<p><form action='examples.php' method='post' enctype='' name='form1' target='_self'><hr \> <label>Example of Textfield</label><br \><br \>Nombre:<input name='Nombre' type='text' value='' size='50' maxlength='50' />Apellido:<input name='Apellido' type='text' value='' size='50' maxlength='50' /><hr \> <label>Example of Text Area</label><br \><br \>Comentario:<textarea name='Comentario' cols='50' rows='10'></textarea><hr \> <label>Example of Button</label><br \><br \><input name='submit' type='submit' value='Submit'></form><hr \> <label>Example of Check Button</label><br \><br \><input name='CheckButtonName' type='checkbox' value='ValueCheckButton' checked='checked'><input name='CheckButtonName' type='checkbox' value='ValueCheckButton'><hr \> <label>Example of Radio Button</label><br \><br \><input name='RadioButtonName' type='radio' value='ValueRadioButton' checked><input name='RadioButtonName' type='radio' value='ValueRadioButton'></form></p>