Variable setting in 'if' for use outside of 'if'
Is there any means of setting variables other than 'with'? As best I can determine, the mechanism for setting variable using 'with' provides those values only within the 'with' block. I would like to preface my html with an if-elif-elif-else block, using it to set a variable so that a simple if-else test can be used later on. I would prefer not to have to replicate the full document within each portion of the if-elif-elif-else block, but I can't find a way to set a variable in the if-elif-elif-else block that can carry over to the rest of the document, since Zope considers it an error for a tag to be only partially contained within a larger block. Please help.
On 10 Feb 99, at 15:45, Shaw, Howard wrote:
Is there any means of setting variables other than 'with'? As best I can determine, the mechanism for setting variable using 'with' provides those values only within the 'with' block.
<!--#call "REQUEST.set('myvariable',1)"--> Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com ICQ: 14856937 We must come down from our heights, and leave our straight paths, for the byways and low places of life, if we would learn truths by strong contrasts; and in hovels, in forecastles, and among our own outcasts in foreign lands, see what has been wrought upon our fellow-creatures by accident, hardship, or vice. - Richard Henry Dana, Jr. 1836
At 03:45 PM 2/10/99 -0600, you wrote:
I would prefer not to have to replicate the full document within each portion of the if-elif-elif-else block, but I can't find a way to set a variable in the if-elif-elif-else block that can carry over to the rest of the document, since Zope considers it an error for a tag to be only partially contained within a larger block.
Please help.
I'm going to piggy back on this question, as I was just about to ask something very similar--I think. Being new to Zope, and coming from the programming school that smaller and faster is better, I attempted to create a page that had a couple of interactive forms, and then a display form built into it. Various sections of the page would become visible depending on which "submit" buttons were pressed when. I actually had all the display stuff working quite nicely, it was just the calculation stuff that was causing me problems. It appeared that when a page was itself the subject of ACTION in a form, a number of variables that were initially set when the first submit button was pressed vanished (became unset) when the second submit button was pressed. This caused me no end of grief. I tried storing some of the required form variables under new names using REQUEST.set(), but this seemed to have no effect. Eventually, I abandoned my approach of trying to cram everything into one page, so I took the first form and made it a page to itelf, the second form got its own page, and the display form also got its own page. I actually liked this as the HTML and the DTML were far easier to follow and it appeared to work nice and fast. Well, I got all the display stuff working correctly across the three documents and then attempted to put in the calculations that were required. I was terribly disappointed to discover that variables that were assigned in Form One, and were displayed in Form Two no longer existed when I got to the form that displayed the results. Here is some highly edited DTML, with my comments added in C++ syntax index_html: <FORM ACTION="detail_html" METHOD="POST"> <table border=1> <th align="center"><B>Desired Margin</B></th> <tr> <td> <input type="radio" name="margin" value="1.12">12%<BR> <input type="radio" name="margin" value="1.17" checked>17%<BR> <input type="radio" name="margin" value="1.27">27%<BR> </td> </tr> </table> <input type="submit" name="MarginBtn" value="Select Margin" align="CENTER"> </FORM> detail_html: <p><b>Margin:</b> <!--#var margin--></p> //This works exactly as it should. It displays the //margin that was selected in index_html <FORM ACTION="form_html" METHOD="POST"> <table border=1> <!--#in PriceCategories--> <tr> <td> <B><!--#var Category--></B> </td> <td> <select name="<!--#var Category-->" size=1> //This is all much nicer thanks to an earlier <!--#in "PriceTable(PriceGroup=Category)"--> //response from Amos Thanks! <option><!--#var Description--> //The fact that it works at all is a testament to <!--#/in--> //Zope's utility, thanks DC. </select> </td> </tr> <!--#/in--> </table> <input type="submit" name="Calculate" value="Calculate" align="CENTER"> </FORM> form_html: <p><b>Margin:</b> <!--#var margin--></p> //This breaks. Why is "margin" undefined when I get here? //Tracebacks show a NameError The rest of the doc deleted as it breaks on the first line. Any help or enlightenment would be tremendously appreciated. -- Stand Fast, tjg. =================================== Timothy J. Grant tjg@avalongroup.net Avalon Technology Group www.avalongroup.net (503) 246-3630 voice (503) 246-3124 fax This message may be digitally signed with PGP. A PGP signature guarantees that this message really did come from me. For more information regarding digital signatures and encryption, please contact me.
At 04:45 PM 2/10/99 -0800, Timothy Grant wrote: ...
I was terribly disappointed to discover that variables that were assigned in Form One, and were displayed in Form Two no longer existed when I got to the form that displayed the results.
This is a basic feature of HTTP, it's stateless. Variables are defined in a given request, but unless you save them in some way they're lost. This scenario is not Zope-specific. Common solutions to this are: * storing information in the browser with cookies * storing information in hidden form elements of returned HTML pages * storing information on the server in "user sessions" which are keyed to cookies, or some kind of URL tagging scheme In your case I suggest using hidden form elements. For example: page1: <form action="page2"> foo: <input type="text"name="foo"> <input type="submit"> </form> page2: <form action="page3"> <input type="hidden" name="foo" value="<!--#var foo-->"> bar: <input type="text" name="bar"> <input type="submit"> </form> page3 foo: <!--#var foo--> bar: <!--#var bar--> Hope this helps. -Amos -- Amos Latteier mailto:amos@digicool.com Digital Creations http://www.digicool.com/
On 10 Feb 99, at 16:45, Timothy Grant wrote:
//margin that was selected in index_html
<FORM ACTION="form_html" METHOD="POST"> <table border=1> <!--#in PriceCategories--> <tr> <td> <B><!--#var Category--></B> </td> <td> <select name="<!--#var Category-->" size=1> //This is all much nicer thanks to an earlier <!--#in "PriceTable(PriceGroup=Category)"--> //response from Amos Thanks! <option><!--#var Description--> //The fact that it works at all is a testament to <!--#/in--> //Zope's utility, thanks DC. </select> </td> </tr> <!--#/in--> </table>
<input type="hidden" name="margin" value="<!--#var margin-->">
<input type="submit" name="Calculate" value="Calculate" align="CENTER"> </FORM>
form_html: <p><b>Margin:</b> <!--#var margin--></p> //This breaks. Why is "margin" undefined when I get here?
Add this to your second form <input type="hidden" name="margin" value="<!--#var margin-->"> as shown above. Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com ICQ: 14856937 We must come down from our heights, and leave our straight paths, for the byways and low places of life, if we would learn truths by strong contrasts; and in hovels, in forecastles, and among our own outcasts in foreign lands, see what has been wrought upon our fellow-creatures by accident, hardship, or vice. - Richard Henry Dana, Jr. 1836
participants (4)
-
Amos Latteier -
Brad Clements -
Shaw, Howard -
Timothy Grant