Re: [Zope] Converting REQUEST style lists into real lists
Tomek Giela writes:
From: Tomek Giela <zope@server.imagination.com.pl> To: zope@zope.org Subject: [Zope] Converting REQUEST style lists into real lists Date: Tue, 24 Jul 2001 04:19:53 +0000
When you put into your form:
<input type="checkbox" name="varia" value="1"> <input type="checkbox" name="varia" value="2"> <input type="checkbox" name="varia" value="3"> <input type="checkbox" name="varia" value="4"> <input type="checkbox" name="varia" value="5"> <input type="checkbox" name="varia" value="6">
and then select first three of them and submit that form, you'll get in form "action" document:
<dtml-var varia>
displayed as: ['1','2','3']
Is there an easy way to convert 'varia' into a list?
Along the same lines, is there a way to have it return a complete array instead of just listing those that were checked? <dtml-var varia> displayed as: ['1','2','3','','',''] Thahnks, Albert
[Albert Ting]
Tomek Giela writes:
From: Tomek Giela <zope@server.imagination.com.pl> To: zope@zope.org Subject: [Zope] Converting REQUEST style lists into real lists Date: Tue, 24 Jul 2001 04:19:53 +0000
When you put into your form:
<input type="checkbox" name="varia" value="1"> <input type="checkbox" name="varia" value="2"> <input type="checkbox" name="varia" value="3"> <input type="checkbox" name="varia" value="4"> <input type="checkbox" name="varia" value="5"> <input type="checkbox" name="varia" value="6">
and then select first three of them and submit that form, you'll get in form "action" document:
<dtml-var varia>
displayed as: ['1','2','3']
Is there an easy way to convert 'varia' into a list?
That ***is*** a list, and you can feed it to <dtml-in> Cheers, Tom P
Thomas B. Passin writes:
From: "Thomas B. Passin" <tpassin@mitretek.org> To: <zope@zope.org> Subject: Re: [Zope] Converting REQUEST style lists into real lists Date: Tue, 24 Jul 2001 10:38:58 -0400
[Albert Ting]
Tomek Giela writes:
From: Tomek Giela <zope@server.imagination.com.pl> To: zope@zope.org Subject: [Zope] Converting REQUEST style lists into real lists Date: Tue, 24 Jul 2001 04:19:53 +0000
When you put into your form:
<input type="checkbox" name="varia" value="1"> <input type="checkbox" name="varia" value="2"> <input type="checkbox" name="varia" value="3"> <input type="checkbox" name="varia" value="4"> <input type="checkbox" name="varia" value="5"> <input type="checkbox" name="varia" value="6">
and then select first three of them and submit that form, you'll get in form "action" document:
<dtml-var varia>
displayed as: ['1','2','3']
Is there an easy way to convert 'varia' into a list?
That ***is*** a list, and you can feed it to <dtml-in>
Cheers,
Tom P
Yes, that is a list, but not the list I'm looking for. What I want is an exhaustive list. If the person selected every other checkbox in the above example, starting with the first one, I want zope to return a six element list like below. ['1','','3','','5',''] Thanks, Albert
Albert L. Ting writes:
... Yes, that is a list, but not the list I'm looking for. What I want is an exhaustive list. If the person selected every other checkbox in the above example, starting with the first one, I want zope to return a six element list like below.
['1','','3','','5',''] Zope cannot do this for you without application knowledge:
As of the HTML spec, a checkbox is only successful, if it is checked. Unsuccessfull form controls do not contribute to the form result set. Zope has no chance to detect them from the request data. Your application (Python Script) can have a list of possible checkbox values and build the list you want from that available in the request. Maybe, URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html helps you to recognize wishes that cannot be fulfilled. Dieter
[Dieter Maurer]
Albert L. Ting writes:
... Yes, that is a list, but not the list I'm looking for. What I want is an exhaustive list. If the person selected every other checkbox in the above example, starting with the first one, I want zope to return a six element list like below.
['1','','3','','5',''] Zope cannot do this for you without application knowledge:
As of the HTML spec, a checkbox is only successful, if it is checked. Unsuccessfull form controls do not contribute to the form result set. Zope has no chance to detect them from the request data.
Your application (Python Script) can have a list of possible checkbox values and build the list you want from that available in the request.
Actually there is another way, purely HTML and forms processing. It's a bit wierd, but it will work. For every check box, include another hidden field of the same name. You can set the value to anything you like, maybe "not checked". Make it a list type field (the checkbox too) by using the ":list" syntax. Then if a check box of the same name has been checked, for that variable name, your REQUEST will contain a list of length 2, but if not you get a list of length one. This is easy to test for with dhtml. Cheers, Tom P
Thomas B. Passin writes:
Actually there is another way, purely HTML and forms processing. It's a bit wierd, but it will work. For every check box, include another hidden field of the same name. You can set the value to anything you like, maybe "not checked". Make it a list type field (the checkbox too) by using the ":list" syntax.
Then if a check box of the same name has been checked, for that variable name, your REQUEST will contain a list of length 2, but if not you get a list of length one. This is easy to test for with dhtml. When I read your reply, I remembered the ":default" variable suffix. It allows to define default values for form fields.
More info: URL:http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html Dieter
[Dieter Maurer]
Thomas B. Passin writes:
Actually there is another way, purely HTML and forms processing. It's a bit wierd, but it will work. For every check box, include another hidden field of the same name. You can set the value to anything you like, maybe "not checked". Make it a list type field (the checkbox too) by using the ":list" syntax.
Then if a check box of the same name has been checked, for that variable name, your REQUEST will contain a list of length 2, but if not you get a list of length one. This is easy to test for with dhtml. When I read your reply, I remembered the ":default" variable suffix. It allows to define default values for form fields.
Ah! Strike another one for Zope! Cheers, Tom P
participants (4)
-
Albert L. Ting -
Albert Ting -
Dieter Maurer -
Thomas B. Passin