|
// Form. php
Class form {
Var $ layout = true; // whether to use table layout
Var $ action; // URL to which the form is submitted
Var $ method;
Var $ enctype = "";
Var $ name = "";
Var $ id = "";
Var $ class = "";
Function form ($ action, $ method = "POST") {// initialize the member variable through the constructor
$ This-> action = $ action;
$ This-> method = $ method;
}
Function form_start (){
$ Text = "\ n ";
} Else {
$ Text ="\ N ";
}
Return $ text;
}
// Text box function
Function form_text ($ name, $ id, $ label_name, $ label_for, $ value = ""){
$ Text ="
$ Text. = "id = \" {$ id }\"";
If (isset ($ value )){
$ Text. = "value = \" {$ value }\"";
}
$ Text. = "/> \ n ";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Password box function
Function form_passwd ($ name, $ id, $ label_name, $ label_for, $ value = ""){
$ Text ="
$ Text. = "id = \" {$ id }\"";
If (isset ($ value )){
$ Text. = "value = \" {$ value }\"";
}
$ Text. = "/> \ n ";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Hide the domain function
Function form_hidden ($ name, $ id, $ label_name, $ label_for, $ value = ""){
$ Text ="
If (isset ($ value )){
$ Text. = "value = \" {$ value }\"";
}
$ Text. = "/> \ n ";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// File domain functions
Function form_file ($ name, $ id, $ label_name, $ label_for, $ size = ""){
$ Text ="
$ Text. = "id = \" {$ id }\"";
If (isset ($ size )){
$ Text. = "size = \" {$ size }\"";
}
$ Text. = "/> \ n ";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Check box function
Function form_checkbox ($ name, $ label = array (), $ label_name, $ label_for = ""){
$ I = 0;
$ Text = array ();
Foreach ($ label as $ id => $ value ){
$ Text [$ I] ="";
$ Text [$ I]. ="{$ Value}";
$ I ++;
}
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Single functions
Function form_radio ($ name, $ label = array (), $ label_name, $ label_for = ""){
$ I = 0;
$ Text = array ();
Foreach ($ label as $ id => $ value ){
$ Text [$ I] ="";
$ Text [$ I]. ="{$ Value}";
$ I ++;
}
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Drop-down menu function
Function form_select ($ id, $ name, $ options = array (), $ selected = false, $ label_name, $ label_for, $ onchange = ""){
If ($ onchange! = ""){
$ Text ="\ N "; } Else { $ Text ="\ N ";
}
Foreach ($ options as $ value => $ key ){
If ($ selected = $ value ){
$ Text. = "\ t{$ Key}\ N ";
} Elseif ($ selected === false ){
$ Text. = "\ t{$ Key}\ N ";
}
}
$ Text. ="";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Multiple-choice list function
Function form_selectmul ($ id, $ name, $ size, $ options = array (), $ label_name, $ label_for ){
$ Text ="\ N "; Foreach ($ options as $ value => $ key ){ $ Text. = "\ t{$ Key}\ N "; } $ Text. ="\ N ";
$ Label = $ this-> form_label ($ label_name, $ label_for );
$ Form_item = $ this-> form_item ($ label, $ text );
Return $ form_item;
}
// Button function
Function form_button ($ id, $ name, $ type, $ value, $ onclick = ""){
$ Text ="
If ($ onclick! = ""){
$ Text. = "onclick = '{$ onclick }'";
}
$ Text. = ">". $ value;
$ Text. =" \ N ";
If ($ this-> layout = true ){
$ Form_item =" |