Displaying the text from a text area
Hi folks, This seems like it should be simple, but I haven't been able to figure it out. I have a text area called "notes" for users to--appropriately enough--enter notes on a transaction. The notes field carries beautifully across two different forms, allowing the user to append information to the field if they need to when they are viewing the second form. I then want to display the entered text in printable/e-mailable form on the third page. I have discovered the following behaviour, that while understandable is not desirable--at least for what I'm implementing: Form 1: <p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> </textarea></p> Form 2: <p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> <!--#var notes--> </textarea></p> Undesirable behaviour one-- Using this method, I end up with a Python List on the third page. The first item in the list is the text that was entered on the first page, the second item on the list is the text that was entered on both the first and second pages. Undesirable behaviour two-- When I go to display the text using <!--#var notes--> not only do I get both items from the list, but I get untranslated CR/LF pairs. Any solutions to either of these little problems would be greatly appreciated. -- Stand Fast, tjg. ======================= Timothy Grant Red Hat Certified Engineer VP Technology/CTO Avalon Technology Group tjg@avalongroup.net www.avalongroup.net (503) 246-3630 (503) 246-3124 Fax
hello, I think I can help you, since I had something similar. By default Zope keeps track of changes, which gives you the python list. You can go around the problem by using "_v" in fron of your variable (subject of earlier discussion today). Secondly, call your notes variable in the second Form "notes2"
Form 1:
<p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> </textarea></p>
Form 2: <p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> ------------>notes2
<!--#var notes--> </textarea></p>
Undesirable behaviour two-- When I go to display the text using <!--#var notes--> not only do I get both items from the list, but I get untranslated CR/LF pairs. I usually use an external method to translate that type of stuff using the string functions.
import string def prepare_view(self, REQUEST): return string.replace(REQUEST.notes, '\r\n', '\n<br>') I hope that helps. stephan -- Stephan Richter iXL - Software Designer and Engineer
Problem 1 occurs because you are using the same name on form 2 for the notes field and this field already exists in the REQUEST from the previous form, which causes Zope to concatenate them into a list. A simple fix is to use different names on each form. Problem 2 can be rectified by using the newline_to_br format on your var i.e. <!--#var "notes" newline_to_br --> which as you can guess converts cr/lf's to <br>'s Robert Leftwich Timothy Grant wrote:
Hi folks,
This seems like it should be simple, but I haven't been able to figure it out.
I have a text area called "notes" for users to--appropriately enough--enter notes on a transaction.
The notes field carries beautifully across two different forms, allowing the user to append information to the field if they need to when they are viewing the second form. I then want to display the entered text in printable/e-mailable form on the third page.
I have discovered the following behaviour, that while understandable is not desirable--at least for what I'm implementing:
Form 1:
<p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> </textarea></p>
Form 2: <p><b>Notes:</b><br> <textarea name="notes" wrap="on" cols="80" rows="10"> <!--#var notes--> </textarea></p>
Undesirable behaviour one--
Using this method, I end up with a Python List on the third page. The first item in the list is the text that was entered on the first page, the second item on the list is the text that was entered on both the first and second pages.
Undesirable behaviour two-- When I go to display the text using <!--#var notes--> not only do I get both items from the list, but I get untranslated CR/LF pairs.
Any solutions to either of these little problems would be greatly appreciated.
-- Stand Fast, tjg.
======================= Timothy Grant Red Hat Certified Engineer VP Technology/CTO Avalon Technology Group tjg@avalongroup.net www.avalongroup.net (503) 246-3630 (503) 246-3124 Fax
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
Robert Leftwich wrote:
Problem 1 occurs because you are using the same name on form 2 for the notes field and this field already exists in the REQUEST from the previous form, which causes Zope to concatenate them into a list. A simple fix is to use different names on each form.
Problem 2 can be rectified by using the newline_to_br format on your var i.e.
Thank you for your help. It was exactly right. -- Stand Fast, tjg. ======================= Timothy Grant Red Hat Certified Engineer VP Technology/CTO Avalon Technology Group tjg@avalongroup.net www.avalongroup.net (503) 246-3630 (503) 246-3124 Fax
participants (3)
-
Robert Leftwich -
Stephan Richter -
Timothy Grant