Form.php
| From: | Hakan Kuecuekyilmaz | Date: | Wed, 10 Oct 2001 08:56:45 +0000 |
| Subject: | Form.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-2223@lists.php.net to get a copy of this message | ||
Hello,
attached you will find some additions and changes that I made to
Form.php.
regards
--
Hakan Kuecuekyilmaz, presently intern at
Tecnomatix Technologies Germany | Tel: +49 711 1389- 257
Mittlerer Pfad 9 | <hakan@lisas.de>
70 499 Stuttgart | <hkuecuekyilmaz@tecnomatix.de>
-------------------------------------------------
This mail sent through IMP: webmail.fht-esslingen.de
<? // Hakan Kuecuekyilmaz <hakan@lisas.de> 2001-10-03 require_once("PEAR.php"); require_once("HTML/Form.php"); class Formular extends HTML_Form { /** ENCTYPE attribute of <FORM> tag */ var $enctype; // overwriting HTML_Form constructor function HTML_Form($action, $method = 'GET', $name = '', $target = '', $enctype = '') { $this->action = $action; $this->method = $method; $this->name = $name; $this->fields = array(); $this->encoding = ''; $this->target = $target; $this->enctype = $enctype; } // constructor function Formular($action, $method = 'GET', $name = '', $target= '', $enctype = '') { // constructor call for HTML_Form $this->HTML_Form($action, $method, $name, $target, $enctype); } // {{{ adding misssing addBlank function function addBlank($i) { $this->fields[] = array("blank", $i); } function displayBlank(){ print " "; } function displayBlankRow($i) { for ($j = 0; $j < $i; $j++) { print " <TR>\n"; print " <TH ALIGN=\"right\"> </TH>"; print " <TD>"; $this->displayBlank(); print "</TD>\n"; print " </TR>\n"; } } // }}} end of addBlank // {{{ addFile function addFile($name, $title, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { $this->fields[] = array("file", $name, $title, $maxsize, $size, $accept); } function displayFile($name, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { print "<INPUT TYPE=\"file\" NAME=\"$name\" MAXSIZE=\"$maxsize\" SIZE=\"$size\""; if ($accept) { print " ACCEPT=\"$accept\""; } print ">"; } function displayFileRow($name, $title, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { print " <TR>\n"; print " <TH ALIGN=\"right\">$title</TH>"; print " <TD>"; $this->displayFile($name, $maxsize, $size, $accept); print "</TD>\n"; print " </TR>\n"; } // }}} end of addFile // overwriting HTML/Form.php function start() { print "<FORM ACTION=\"" . basename($this->action) . "\" METHOD=\"$this->method\""; if ($this->name) { print " NAME=\"$this->name\""; } if ($this->target) { print " TARGET=\"$this->target\""; } if ($this->enctype) { print " ENCTYPE=\"$this->enctype\""; } print ">\n"; } // {{{ addText function addText($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { $this->fields[] = array("text", $name, $title, $default, $size, $maxlength); } function displayText($name, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { print "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\" MAXLENGTH=\"$maxlength\">"; } function displayTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { print " <TR>\n"; print " <TH ALIGN=\"right\">$title</TH>"; print " <TD>"; $this->displayText($name, $default, $size, $maxlength); print "</TD>\n"; print " </TR>\n"; } // }}} end of addText function addTextarea($name, $title, $default, $width = HTML_FORM_TEXTAREA_WT, $height = HTML_FORM_TEXTAREA_HT, $maxlength) { $this->fields[] = array("textarea", $name, $title, &$default, $width, $height, $maxlength); } function displayTextarea($name, $default = '', $width = 40, $height = 5, $maxlength) { print "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\" MAXLENGTH=\"$maxlength\">"; print $default; print "</TEXTAREA>"; } function displayTextareaRow($name, $title, $default = '', $width = 40, $height = 5, $maxlength) { print " <TR>\n"; print " <TH ALIGN=\"right\" VALIGN=\"top\">$title</TH>\n"; print " <TD>"; $this->displayTextarea($name, &$default, $width, $height, $maxlength); print "</TD>\n"; print " </TR>\n"; } function display() { $arrname = 'HTTP_'.strtoupper($this->method).'_VARS'; $arr = &$GLOBALS[$arrname]; $this->start(); print "<TABLE>\n"; reset($this->fields); $hidden = array(); foreach ($this->fields as $i => $data) { switch ($data[0]) { case "hidden": $hidden[] = $i; $defind = 0; continue 2; case "reset": case "blank": // new $params = 1; $defind = 0; break; case "submit": case "image": $params = 2; $defind = 0; break; case "checkbox": $params = 3; $defind = 2; break; case "text": case "password": case "radio": case "file": //new $params = 5; // original value 4 (maxlength) $defind = 3; break; case "textarea": $params = 6; // original value 5 (maxlength) $defind = 3; break; case "select": $params = 8; $defind = 4; break; default: // unknown field type continue 2; } $str = '$this->display'.ucfirst($data[0])."Row("; for ($i = 1; $i <= $params; $i++) { if ($i == $defind && $data[$defind] === null && isset($arr[$data[1]])) { $str .= "\$arr['$data[1]']"; } else { $str .= '$'."data[$i]"; } if ($i < $params) $str .= ', '; } $str .= ');'; eval($str); } print "</TABLE>\n"; for ($i = 0; $i < sizeof($hidden); $i++) { $this->displayHidden($this->fields[$hidden[$i]][1], $this->fields[$hidden[$i]][2]); } $this->end(); } // end of overwriting HTML/Form.php } ?>
<? // Hakan Kuecuekyilmaz <hakan@lisas.de> 2001-10-03 require_once("PEAR.php"); require_once("HTML/Form.php"); class Formular extends HTML_Form { /** ENCTYPE attribute of <FORM> tag */ var $enctype; // overwriting HTML_Form constructor function HTML_Form($action, $method = 'GET', $name = '', $target = '', $enctype = '') { $this->action = $action; $this->method = $method; $this->name = $name; $this->fields = array(); $this->encoding = ''; $this->target = $target; $this->enctype = $enctype; } // constructor function Formular($action, $method = 'GET', $name = '', $target= '', $enctype = '') { // constructor call for HTML_Form $this->HTML_Form($action, $method, $name, $target, $enctype); } // {{{ adding misssing addBlank function function addBlank($i) { $this->fields[] = array("blank", $i); } function displayBlank(){ print " "; } function displayBlankRow($i) { for ($j = 0; $j < $i; $j++) { print " <TR>\n"; print " <TH ALIGN=\"right\"> </TH>"; print " <TD>"; $this->displayBlank(); print "</TD>\n"; print " </TR>\n"; } } // }}} end of addBlank // {{{ addFile function addFile($name, $title, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { $this->fields[] = array("file", $name, $title, $maxsize, $size, $accept); } function displayFile($name, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { print "<INPUT TYPE=\"file\" NAME=\"$name\" MAXSIZE=\"$maxsize\" SIZE=\"$size\""; if ($accept) { print " ACCEPT=\"$accept\""; } print ">"; } function displayFileRow($name, $title, $maxsize = Html_Form_Max_File_Size, $size = Html_Form_Text_Size, $accept = '') { print " <TR>\n"; print " <TH ALIGN=\"right\">$title</TH>"; print " <TD>"; $this->displayFile($name, $maxsize, $size, $accept); print "</TD>\n"; print " </TR>\n"; } // }}} end of addFile // overwriting HTML/Form.php function start() { print "<FORM ACTION=\"" . basename($this->action) . "\" METHOD=\"$this->method\""; if ($this->name) { print " NAME=\"$this->name\""; } if ($this->target) { print " TARGET=\"$this->target\""; } if ($this->enctype) { print " ENCTYPE=\"$this->enctype\""; } print ">\n"; } // {{{ addText function addText($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { $this->fields[] = array("text", $name, $title, $default, $size, $maxlength); } function displayText($name, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { print "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\" MAXLENGTH=\"$maxlength\">"; } function displayTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE, $maxlength) { print " <TR>\n"; print " <TH ALIGN=\"right\">$title</TH>"; print " <TD>"; $this->displayText($name, $default, $size, $maxlength); print "</TD>\n"; print " </TR>\n"; } // }}} end of addText function addTextarea($name, $title, $default, $width = HTML_FORM_TEXTAREA_WT, $height = HTML_FORM_TEXTAREA_HT, $maxlength) { $this->fields[] = array("textarea", $name, $title, &$default, $width, $height, $maxlength); } function displayTextarea($name, $default = '', $width = 40, $height = 5, $maxlength) { print "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\" MAXLENGTH=\"$maxlength\">"; print $default; print "</TEXTAREA>"; } function displayTextareaRow($name, $title, $default = '', $width = 40, $height = 5, $maxlength) { print " <TR>\n"; print " <TH ALIGN=\"right\" VALIGN=\"top\">$title</TH>\n"; print " <TD>"; $this->displayTextarea($name, &$default, $width, $height, $maxlength); print "</TD>\n"; print " </TR>\n"; } function display() { $arrname = 'HTTP_'.strtoupper($this->method).'_VARS'; $arr = &$GLOBALS[$arrname]; $this->start(); print "<TABLE>\n"; reset($this->fields); $hidden = array(); foreach ($this->fields as $i => $data) { switch ($data[0]) { case "hidden": $hidden[] = $i; $defind = 0; continue 2; case "reset": case "blank": // new $params = 1; $defind = 0; break; case "submit": case "image": $params = 2; $defind = 0; break; case "checkbox": $params = 3; $defind = 2; break; case "text": case "password": case "radio": case "file": //new $params = 5; // original value 4 (maxlength) $defind = 3; break; case "textarea": $params = 6; // original value 5 (maxlength) $defind = 3; break; case "select": $params = 8; $defind = 4; break; default: // unknown field type continue 2; } $str = '$this->display'.ucfirst($data[0])."Row("; for ($i = 1; $i <= $params; $i++) { if ($i == $defind && $data[$defind] === null && isset($arr[$data[1]])) { $str .= "\$arr['$data[1]']"; } else { $str .= '$'."data[$i]"; } if ($i < $params) $str .= ', '; } $str .= ');'; eval($str); } print "</TABLE>\n"; for ($i = 0; $i < sizeof($hidden); $i++) { $this->displayHidden($this->fields[$hidden[$i]][1], $this->fields[$hidden[$i]][2]); } $this->end(); } // end of overwriting HTML/Form.php } ?>