adding Plaintext to HTML::Form
| From: | Ted Shieh | Date: | Mon, 25 Feb 2002 08:10:52 +0000 |
| Subject: | adding Plaintext to HTML::Form | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-4860@lists.php.net to get a copy of this message | ||
I'd like to submit the following patch to HTML::Form. Here is the patch in diff -u form:
----------------------------------------------------------
--- Form-old.php Wed Jan 30 04:26:26 2002
+++ Form-tedshieh.php Sun Feb 17 15:47:34 2002
@@ -17,7 +17,7 @@
// | Urs Gehrig <urs@circle.ch> |// +----------------------------------------------------------------------+ // -// $Id: Form.php,v 1.22 2002/01/30 09:26:25 ssb Exp $ +// $Id: Form.php,v 1.2 2002/02/14 01:30:57 Ted Shieh Exp $ // // HTML form utility functions. // @@ -178,6 +178,14 @@
}
// }}}
+ // {{{ addPlaintext()
+
+ function addPlaintext($title, $text)
+ {
+ $this->fields[] = array("plaintext", $title, $text);
+ }
+
+ // }}}
// {{{ start()
function start()@@ -468,6 +476,27 @@
}
// }}}
+ // {{{ displayPlaintext()
+
+ function displayPlaintext($text = '')
+ {
+ print $text;
+ }
+
+ // }}}
+ // {{{ displayPlaintextRow()
+
+ function displayPlaintextRow($title, $text = '')
+ {
+ print " <tr>\n";
+ print " <th align=\"right\" valign=\"top\">$title</th>";
+ print " <td>";
+ $this->displayPlaintext($text);
+ print "</td>\n";
+ print " </tr>\n";
+ }
+
+ // }}}
// {{{ returnText()
@@ -747,6 +776,29 @@
}
// }}}
+ // {{{ returnPlaintext()
+
+ function returnPlaintext($text = '')
+ {
+ return $text;
+ }
+
+ // }}}
+ // {{{ returnPlaintextRow()
+
+ function returnPlaintextRow($title, $text = '')
+ {
+ $str = " <tr>\n";
+ $str .= " <th align=\"right\">$title:</th>";
+ $str .= " <td>";
+ $str .= $this->returnPlaintext($text);
+ $str .= "</td>\n";
+ $str .= " </tr>\n";
+
+ return $str; + }+
+ // }}}
// {{{ display()
@@ -798,6 +850,10 @@
case "select":
$params = 8;
$defind = 4;
+ break;
+ case "plaintext":
+ $params = 2;
+ $defind = 0;
break;
default:
// unknown field type
----------------------------------------------------------
This patch adds a new form field type called Plaintext. This is useful for printing text in a form that the user is not supposed to edit.
Here is some sample code that use Plaintext:
if ($user_owns_this_entry) {
$form->addText('input[title]','Subject',stripSlashes($input['title']),60);
$form->addTextArea('input[body]','Entry',stripSlashes($input['body']),60,20);
} else {
$form->addPlaintext('subject',stripSlashes($title));
$form->addPlaintext('entry',nl2br(stripSlashes($body)));
}
$form->addSelect('input[rating]',$rating_title,$rating_options,$default_rating);
$form->addSubmit();
$form->display();
You can see this in action at http://www.liquidmarkets.com/m.php?m=rating&iid=33&cat=kmart_supporters and http://www.liquidmarkets.com/m.php?m=rating&iid=30&cat=kmart_supporters
At the first URL, the text is not editable (shows up as Plaintext) becaues it is owned by another user. At the second URL, the text is editable (shows up in a Textfield) because it is owned by the Anonymous user. I would have liked to have called this Text instead of Plaintext, but Text is used for Textfields.
Ted Shieh
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.