Re: adding Plaintext to HTML::Form
| From: | Ted Shieh | Date: | Mon, 25 Feb 2002 08:47:38 +0000 |
| Subject: | Re: adding Plaintext to HTML::Form | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-4862@lists.php.net to get a copy of this message | ||
addBlank() and addPlaintext() differ in a significant way. This becomes apparent when when we compare displayBlank() and displayPlaintext():
function displayBlank()
{
print " ";} function displayPlaintext($text = '') {
print $text;} You can print a left-hand title label with addBlank(), but you can only put spaces into the right-hand "body." With displayPlaintext(), you can print text of your choice in the right-hand "body" portion. Let me make illustrate this with an example. Look at http://www.liquidmarkets.com/m.php?m=rating&iid=33&cat=kmart_supporters With addBlank(), I can add the part that says "Subject," but not the part that says "Friar Tuck's and Apple Annie's restaurants 10% discount 2002-02-13." I need addPlaintext() for that. Ted Shieh
From: Hakan Kuecuekyilmaz <hakubw00@fht-esslingen.de> To: liquidm1@liquidmarkets.com CC: pear-dev@lists.php.net Subject: Re: [PEAR-DEV] adding Plaintext to HTML::Form Date: Mon, 25 Feb 2002 09:22:31 +0100 This is also possible with addBlank() regards Ted Shieh wrote:_________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.comI'd like to submit the following patch to HTML::Form. Here is the patch in diff -u form: ------------------------------------------------------------ Hakan Kuecuekyilmaz, University of Applied Sciences Esslingen, Germany <hakan@php.net> | <hakan@lisas.de> | <hakan.kuecuekyilmaz@c-cn.de>--- 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.Studenten, Absolventen und Young Professionals <http://www.c-cn.de>-- PEAR Development Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php