<?php
class Chtml
{
public static function open_form($method, $action,$enctype="application/x-www-form-urlencoded", $name="")
{
if ($name!="")
{
$name="name=\"".$name . "\"";
}
return "
<form method=\"$method\" action=\"$action\" enctype=\"$enctype\" $name>
";
}
public static function open_fieldset($style="")
{
if($style!=="")
{
$style=" style=\"" . $style ."\"";
}
return "
<fieldset$style>
";
}
public static function close_fieldset()
{
return "</fieldset>";
}
public static function close_form()
{
return "</form>";
}
public static function create_legend($text)
{
return "<legend>$text</legend>";
}
public static function create_label($id, $text)
{
return "<label for=\"$id\">$text</label>";
}
public static function create_textbox($name, $id, $value="", $size="50", $maxlength="90")
{
return "<input type=\"text\" name=\"$name\" id=\"$id\" size=\"$size\" maxlength=\"$maxlength\" value=\"$value\"/> ";
}
public static function create_field_buttons()
{
return "<input type=\"submit\"> <input type=\"reset\">";
}
public static function create_selectbox($name, $id, $selected_key, &$array_to_show)
{
$temp="<select name=\"$name\" id=\"$id\">";
foreach($array_to_show as $key=>$opt)
{
if ($key==$selected_key)
{
$temp.="<option value=\"$key\" selected=\"selected\">$opt</option>";
continue;
}
$temp.="<option value=\"$key\">$opt</option>";
}
return $temp.="</select>";
}
public static function create_textarea($name, $id, $value="", $cols=50, $rows=10)
{
return "<textarea cols=\"$cols\" rows=\"$rows\" name=\"$name\" id=\"$id\">$value</textarea>";
}
public static function create_hiddenfield($name, $value)
{
return "<input type=\"hidden\" name=\"$name\" value=\"$value\" />";
}
public static function create_radiobuttons ($name, $id, $selected, $array_to_show)
{
foreach($array_to_show as $key=>$radio)
{
if ($key==$selected)
{
$temp.="<input type=\"radio\" value=\"$key\" name=\"$name\" checked=\"checked\" /> $radio<br />";
continue;
}
$temp.="<input type=\"radio\" value=\"$key\" name=\"$name\" /> $radio<br />";
}
return $temp;
}
public static function create_checkbox($name, $id,$title, $value, $checked=false)
{
if ($checked)
{
return "<input type=\"checkbox\" name=\"$name\" value=\"$value\" checked=\"checked\" /> $title <br>";
}
return "<input type=\"checkbox\" name=\"$name\" value=\"$value\" /> $title <br>";
}
}
$country=array(
'austria'=> "Österreich",
'germany'=> "Deutschland",
'spanish'=> "Spanisch",
'greek' => "Griechenland",
);
$radio=array(
'1'=>'eins',
'2'=>'zwei',
'3'=>'drei',
'4'=>'vier'
);
/*
Zum Testen
*/
print Chtml::open_form("POST", $_SERVER['PHP_SELF'] );
print Chtml::open_fieldset();
print Chtml::create_legend("");
print Chtml::create_label('vorname' , 'Vorname') . '<br />';
print Chtml::create_textbox('txt_vorname', 'vorname', $_POST['txt_vorname']). '<br />';
print Chtml::create_label('nachname' , 'Nachname') . '<br />';
print Chtml::create_textbox('txt_name', 'name', $_POST['txt_name']) .'<br />';
print Chtml::create_label('land', 'Land') . '<br />';
print Chtml::create_selectbox('land', 'land',$_POST['land'], $country) .'<br />';
print Chtml::create_label('beschreibung', "Beschreibung") . '<br>';
print Chtml::create_textarea('txt_beschreibung', 'beschreibung', $_POST['txt_beschreibung']).'<br>';
print Chtml::create_radiobuttons("radiobtn", "radiobtn", '3', $radio);
print Chtml::create_checkbox("bla1", "bla1","bla1 Aktivieren", true, true);
print Chtml::create_checkbox("bla2", "bla2","bla2 Aktivieren", true, false);
print Chtml::create_checkbox("bla3", "bla3","bla3 Aktivieren", true, false);
print '<br />'.Chtml::create_field_buttons();
print Chtml::close_fieldset();
print Chtml::close_form();
?>