Patches to HTML/Form
| From: | Alexander Skwar | Date: | Sat, 05 May 2001 23:38:36 +0000 |
| Subject: | Patches to HTML/Form | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-347@lists.php.net to get a copy of this message | ||
Hello.
Attached is a diff against HTML/Form.php. The patch makes all the displayXY
methods call the corresponding returnXY method and print its output.
Because of this, the filesize went down and there is no redundant code
anymore in the file.
Further I introduced a new toHtml method which works just like the old
HTML_Form::display method, with the small difference that it doesn't print
the output, but return it as a string. display now calls toHtml.
Lastly there are some small whitespace changes - some functions were
indented with TABs; I've changed this to the format used in the file - 4
spaces.
The diff is against version 1.8 of HTML/Form.php.
Please review the diff and maybe aply it, if you see fit.
Thanks,
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.digitalprojects.com | http://www.iso-top.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 1 day 7 hours 5 minutes
--- Form.php.Original Sat May 5 23:46:31 2001 +++ Form.php Sun May 6 01:13:51 2001 @@ -147,30 +147,14 @@ // {{{ start() 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\""; - } - print ">"; + print $this->returnStart(); } // }}} // {{{ end() function end() { - $fields = array(); - reset($this->fields); - while (list($i, $data) = each($this->fields)) { - if ($data[0] == 'reset') { - continue; - } - $fields[$data[1]] = true; - } - $this->displayHidden("_fields", implode(":", array_keys($fields))); - print "</FORM>"; + print $this->returnEnd(); } // }}} @@ -178,84 +162,56 @@ // {{{ displayText() function displayText($name, $default = '', $size = HTML_FORM_TEXT_SIZE) { - print "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\">"; + print $this->returnText($name, $default, $size); } // }}} // {{{ displayTextRow() function displayTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE) { - print " <TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>"; - print " <TD>"; - $this->displayText($name, $default, $size); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnTextRow($name, $title, $default, $size); } // }}} // {{{ displayPassword() function displayPassword($name, $default = '', $size = HTML_FORM_PASSWD_SIZE) { - print "<INPUT NAME=\"$name\" TYPE=\"password\" VALUE=\"$default\" SIZE=\"$size\">"; + print $this->returnPassword($name, $default, $size); } // }}} // {{{ displayPasswordRow() function displayPasswordRow($name, $title, $default = '', $size = HTML_FORM_PASSWD_SIZE) { - print "<TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>\n"; - print " <TD>"; - $this->displayPassword($name, $default, $size); - print " repeat: "; - $this->displayPassword($name."2", $default, $size); - print "</TD>\n"; - print "</TR>\n"; + print $this->returnPasswordRow($name, $title, $default, $size); } // }}} // {{{ displayCheckbox() function displayCheckbox($name, $default = false) { - print "<INPUT TYPE=\"checkbox\" NAME=\"$name\""; - if ($default && $default != 'off') { - print " CHECKED"; - } - print ">"; + print $this->returnCheckbox($name, $default); } // }}} // {{{ displayCheckboxRow() function displayCheckboxRow($name, $title, $default = false) { - print " <TR>\n"; - print " <TH ALIGN=\"left\">$title</TH>"; - print " <TD>"; - $this->displayCheckbox($name, $default); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnCheckboxRow($name, $title, $default); } // }}} // {{{ displayTextarea() function displayTextarea($name, $default = '', $width = 40, $height = 5) { - print "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\">"; - print $default; - print "</TEXTAREA>"; + print $this->returnTextare($name, $default, $width, $height); } // }}} // {{{ displayTextareaRow() function displayTextareaRow($name, $title, $default = '', $width = 40, $height = 5) { - print " <TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>\n"; - print " <TD>"; - $this->displayTextarea($name, &$default, $width, $height); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnTextareaRow($name, $title, $default, $width, $height); } // }}} @@ -269,7 +225,7 @@ // {{{ displaySubmitRow() function displaySubmitRow($name = "submit", $title = 'Submit Changes') { - print $this->returnSubmitRow($name, $title); + print $this->returnSubmitRow($name, $title); } // }}} @@ -291,8 +247,8 @@ function displaySelect($name, $entries, $default = '', $size = 1, $blank = '', $multiple = false, $attribs = '') { - print $this->returnSelect($name, $entries, $default, $size, $blank, - $multiple, $attribs); + print $this->returnSelect($name, $entries, $default, $size, $blank, + $multiple, $attribs); } // }}} @@ -301,19 +257,26 @@ function displaySelectRow($name, $title, &$entries, $default = '', $size = 1, $blank = '', $multiple = false) { - print $this->returnSelectRow($name, $title, $entries, $default, $size, - $blank, $multiple); + print $this->returnSelectRow($name, $title, $entries, $default, $size, + $blank, $multiple); } // }}} // {{{ displayHidden() function displayHidden($name, $value) { - print $this->returnHidden($name, $value); + print $this->returnHidden($name, $value); } // }}} + // {{{ display() + + function display() { + print $this->toHtml(); + } + + // }}} // XXX missing: displayRadio displayRadioRow // {{{ returnText() @@ -457,10 +420,10 @@ // {{{ returnSelect() function returnSelect($name, $entries, $default = '', $size = 1, - $blank = '', $multiple = false, $attrib = '') { - if ($multiple && substr($name, -2) != "[]") { - $name .= "[]"; - } + $blank = '', $multiple = false, $attrib = '') { + if ($multiple && substr($name, -2) != "[]") { + $name .= "[]"; + } $str .= " <SELECT NAME=\"$name\""; if ($size) { $str .= " SIZE=\"$size\""; @@ -468,25 +431,25 @@ if ($multiple) { $str .= " MULTIPLE"; } - if ($attrib) { - $str .= " $attrib"; - } + if ($attrib) { + $str .= " $attrib"; + } $str .= ">\n"; if ($blank) { $str .= " <OPTION VALUE=\"\">$blank\n"; } while (list($val, $text) = each($entries)) { $str .= ' <OPTION '; - if ($default) { - if ($multiple && is_array($default)) { - if ((is_string(key($default)) && $default[$val]) || - (is_int(key($default)) && in_array($val, $default))) { - $str .= 'SELECTED '; - } - } elseif ($default == $val) { - $str .= 'SELECTED '; - } - } + if ($default) { + if ($multiple && is_array($default)) { + if ((is_string(key($default)) && $default[$val]) || + (is_int(key($default)) && in_array($val, $default))) { + $str .= 'SELECTED '; + } + } elseif ($default == $val) { + $str .= 'SELECTED '; + } + } $str .= "VALUE=\"$val\">$text\n"; } $str .= " </SELECT>\n"; @@ -498,8 +461,7 @@ // {{{ returnSelectRow() function returnSelectRow($name, $title, &$entries, $default = '', $size = 1, - $blank = '', $multiple = false) - { + $blank = '', $multiple = false) { $str .= " <TR>\n"; $str .= " <TH ALIGN=\"right\">$title:</TH>\n"; $str .= " <TD>\n"; @@ -545,6 +507,10 @@ if ($this->name) { $str .= " NAME=\"$this->name\""; } + // ASkwar: Added support for target as in $this->start(); + if ($this->target) { + print " TARGET=\"$this->target\""; + } if ($multipartformdata) { $str .= " ENCTYPE=\"multipart/form-data\""; } @@ -565,18 +531,19 @@ } $fields[$data[1]] = true; } - $ret = $this->returnHidden("_fields", implode(":", array_keys($fields))); - $ret .= "</FORM>"; - return $ret; + $ret = $this->returnHidden("_fields", implode(":", array_keys($fields))); + $ret .= "</FORM>"; + + return $ret; } // }}} - - // {{{ display() - - function display() { - $this->start(); - print "<TABLE>\n"; + + // {{{ toHtml() + + function toHtml() { + $ret_str = $this->returnStart(); + $ret_str .= "<TABLE>\n"; reset($this->fields); $hidden = array(); $call_cache = array(); @@ -612,7 +579,7 @@ } $str = $call_cache[$data[0]]; if (empty($str)) { - $str = '$this->display'.ucfirst($data[0])."Row("; + $str = '$this->return'.ucfirst($data[0])."Row("; for ($i = 1; $i <= $params; $i++) { $str .= '$data['.$i.']'; if ($i < $params) $str .= ', '; @@ -620,17 +587,20 @@ $str .= ');'; $call_cache[$data[0]] = $str; } - eval($str); + $ret_str .= eval($str); } - print "</TABLE>\n"; + $ret_str .= "</TABLE>\n"; for ($i = 0; $i < sizeof($hidden); $i++) { - $this->displayHidden($this->fields[$hidden[$i]][1], - $this->fields[$hidden[$i]][2]); + $ret_str .= $this->returnHidden($this->fields[$hidden[$i]][1], + $this->fields[$hidden[$i]][2]); } - $this->end(); + $ret_str .= $this->returnEnd(); + + return $ret_str; } - + // }}} + } /*
--- Form.php.Original Sat May 5 23:46:31 2001 +++ Form.php Sun May 6 01:13:51 2001 @@ -147,30 +147,14 @@ // {{{ start() 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\""; - } - print ">"; + print $this->returnStart(); } // }}} // {{{ end() function end() { - $fields = array(); - reset($this->fields); - while (list($i, $data) = each($this->fields)) { - if ($data[0] == 'reset') { - continue; - } - $fields[$data[1]] = true; - } - $this->displayHidden("_fields", implode(":", array_keys($fields))); - print "</FORM>"; + print $this->returnEnd(); } // }}} @@ -178,84 +162,56 @@ // {{{ displayText() function displayText($name, $default = '', $size = HTML_FORM_TEXT_SIZE) { - print "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\">"; + print $this->returnText($name, $default, $size); } // }}} // {{{ displayTextRow() function displayTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE) { - print " <TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>"; - print " <TD>"; - $this->displayText($name, $default, $size); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnTextRow($name, $title, $default, $size); } // }}} // {{{ displayPassword() function displayPassword($name, $default = '', $size = HTML_FORM_PASSWD_SIZE) { - print "<INPUT NAME=\"$name\" TYPE=\"password\" VALUE=\"$default\" SIZE=\"$size\">"; + print $this->returnPassword($name, $default, $size); } // }}} // {{{ displayPasswordRow() function displayPasswordRow($name, $title, $default = '', $size = HTML_FORM_PASSWD_SIZE) { - print "<TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>\n"; - print " <TD>"; - $this->displayPassword($name, $default, $size); - print " repeat: "; - $this->displayPassword($name."2", $default, $size); - print "</TD>\n"; - print "</TR>\n"; + print $this->returnPasswordRow($name, $title, $default, $size); } // }}} // {{{ displayCheckbox() function displayCheckbox($name, $default = false) { - print "<INPUT TYPE=\"checkbox\" NAME=\"$name\""; - if ($default && $default != 'off') { - print " CHECKED"; - } - print ">"; + print $this->returnCheckbox($name, $default); } // }}} // {{{ displayCheckboxRow() function displayCheckboxRow($name, $title, $default = false) { - print " <TR>\n"; - print " <TH ALIGN=\"left\">$title</TH>"; - print " <TD>"; - $this->displayCheckbox($name, $default); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnCheckboxRow($name, $title, $default); } // }}} // {{{ displayTextarea() function displayTextarea($name, $default = '', $width = 40, $height = 5) { - print "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\">"; - print $default; - print "</TEXTAREA>"; + print $this->returnTextare($name, $default, $width, $height); } // }}} // {{{ displayTextareaRow() function displayTextareaRow($name, $title, $default = '', $width = 40, $height = 5) { - print " <TR>\n"; - print " <TH ALIGN=\"right\">$title</TH>\n"; - print " <TD>"; - $this->displayTextarea($name, &$default, $width, $height); - print "</TD>\n"; - print " </TR>\n"; + print $this->returnTextareaRow($name, $title, $default, $width, $height); } // }}} @@ -269,7 +225,7 @@ // {{{ displaySubmitRow() function displaySubmitRow($name = "submit", $title = 'Submit Changes') { - print $this->returnSubmitRow($name, $title); + print $this->returnSubmitRow($name, $title); } // }}} @@ -291,8 +247,8 @@ function displaySelect($name, $entries, $default = '', $size = 1, $blank = '', $multiple = false, $attribs = '') { - print $this->returnSelect($name, $entries, $default, $size, $blank, - $multiple, $attribs); + print $this->returnSelect($name, $entries, $default, $size, $blank, + $multiple, $attribs); } // }}} @@ -301,19 +257,26 @@ function displaySelectRow($name, $title, &$entries, $default = '', $size = 1, $blank = '', $multiple = false) { - print $this->returnSelectRow($name, $title, $entries, $default, $size, - $blank, $multiple); + print $this->returnSelectRow($name, $title, $entries, $default, $size, + $blank, $multiple); } // }}} // {{{ displayHidden() function displayHidden($name, $value) { - print $this->returnHidden($name, $value); + print $this->returnHidden($name, $value); } // }}} + // {{{ display() + + function display() { + print $this->toHtml(); + } + + // }}} // XXX missing: displayRadio displayRadioRow // {{{ returnText() @@ -457,10 +420,10 @@ // {{{ returnSelect() function returnSelect($name, $entries, $default = '', $size = 1, - $blank = '', $multiple = false, $attrib = '') { - if ($multiple && substr($name, -2) != "[]") { - $name .= "[]"; - } + $blank = '', $multiple = false, $attrib = '') { + if ($multiple && substr($name, -2) != "[]") { + $name .= "[]"; + } $str .= " <SELECT NAME=\"$name\""; if ($size) { $str .= " SIZE=\"$size\""; @@ -468,25 +431,25 @@ if ($multiple) { $str .= " MULTIPLE"; } - if ($attrib) { - $str .= " $attrib"; - } + if ($attrib) { + $str .= " $attrib"; + } $str .= ">\n"; if ($blank) { $str .= " <OPTION VALUE=\"\">$blank\n"; } while (list($val, $text) = each($entries)) { $str .= ' <OPTION '; - if ($default) { - if ($multiple && is_array($default)) { - if ((is_string(key($default)) && $default[$val]) || - (is_int(key($default)) && in_array($val, $default))) { - $str .= 'SELECTED '; - } - } elseif ($default == $val) { - $str .= 'SELECTED '; - } - } + if ($default) { + if ($multiple && is_array($default)) { + if ((is_string(key($default)) && $default[$val]) || + (is_int(key($default)) && in_array($val, $default))) { + $str .= 'SELECTED '; + } + } elseif ($default == $val) { + $str .= 'SELECTED '; + } + } $str .= "VALUE=\"$val\">$text\n"; } $str .= " </SELECT>\n"; @@ -498,8 +461,7 @@ // {{{ returnSelectRow() function returnSelectRow($name, $title, &$entries, $default = '', $size = 1, - $blank = '', $multiple = false) - { + $blank = '', $multiple = false) { $str .= " <TR>\n"; $str .= " <TH ALIGN=\"right\">$title:</TH>\n"; $str .= " <TD>\n"; @@ -545,6 +507,10 @@ if ($this->name) { $str .= " NAME=\"$this->name\""; } + // ASkwar: Added support for target as in $this->start(); + if ($this->target) { + print " TARGET=\"$this->target\""; + } if ($multipartformdata) { $str .= " ENCTYPE=\"multipart/form-data\""; } @@ -565,18 +531,19 @@ } $fields[$data[1]] = true; } - $ret = $this->returnHidden("_fields", implode(":", array_keys($fields))); - $ret .= "</FORM>"; - return $ret; + $ret = $this->returnHidden("_fields", implode(":", array_keys($fields))); + $ret .= "</FORM>"; + + return $ret; } // }}} - - // {{{ display() - - function display() { - $this->start(); - print "<TABLE>\n"; + + // {{{ toHtml() + + function toHtml() { + $ret_str = $this->returnStart(); + $ret_str .= "<TABLE>\n"; reset($this->fields); $hidden = array(); $call_cache = array(); @@ -612,7 +579,7 @@ } $str = $call_cache[$data[0]]; if (empty($str)) { - $str = '$this->display'.ucfirst($data[0])."Row("; + $str = '$this->return'.ucfirst($data[0])."Row("; for ($i = 1; $i <= $params; $i++) { $str .= '$data['.$i.']'; if ($i < $params) $str .= ', '; @@ -620,17 +587,20 @@ $str .= ');'; $call_cache[$data[0]] = $str; } - eval($str); + $ret_str .= eval($str); } - print "</TABLE>\n"; + $ret_str .= "</TABLE>\n"; for ($i = 0; $i < sizeof($hidden); $i++) { - $this->displayHidden($this->fields[$hidden[$i]][1], - $this->fields[$hidden[$i]][2]); + $ret_str .= $this->returnHidden($this->fields[$hidden[$i]][1], + $this->fields[$hidden[$i]][2]); } - $this->end(); + $ret_str .= $this->returnEnd(); + + return $ret_str; } - + // }}} + } /*