I have a form variable whose value is being passed to a DTML method upon form submission. In this DTML method, I use the form variable as input to a <dtml-in>. When this form variable is passed as a list(i.e. it contains multiple values), everything works fine. However, when this form variable is passed as a string(i.e. it contains a single value), <dtml-in> complains that it is being passed an input of the wrong type. Is there a way to detect whether this form variable is a list or string? Using the len function doesn't work because len works on both strings and lists. One solution I have figured out uses a HTML hidden variable to set the form variable to a default value. This guarantees that the form variable is always a list since a minimum of 2 values are passed upon form submission. However, this is a hack and I'd rather use something more elegant. Any help would be greatly appreciated. Thanks. - Asad
On Wed, Sep 22, 2004 at 02:20:40PM -0400, Asad Habib wrote:
I have a form variable whose value is being passed to a DTML method upon form submission. In this DTML method, I use the form variable as input to a <dtml-in>. When this form variable is passed as a list(i.e. it contains multiple values), everything works fine. However, when this form variable is passed as a string(i.e. it contains a single value), <dtml-in> complains that it is being passed an input of the wrong type. Is there a way to detect whether this form variable is a list or string? Using the len function doesn't work because len works on both strings and lists.
One solution I have figured out uses a HTML hidden variable to set the form variable to a default value. This guarantees that the form variable is always a list since a minimum of 2 values are passed upon form submission. However, this is a hack and I'd rather use something more elegant.
In your form, append ":list" to the variable's name. e.g. <input type="text" name="my_variable:list"> .... This is documented in the "Advanced Scripting" chapter of the online zope book. -- Paul Winkler http://www.slinkp.com
----- Original Message ----- From: "Asad Habib" <ahabib@engin.umich.edu>
I have a form variable whose value is being passed to a DTML method upon form submission. In this DTML method, I use the form variable as input to a <dtml-in>. When this form variable is passed as a list(i.e. it contains multiple values), everything works fine. However, when this form variable is passed as a string(i.e. it contains a single value), <dtml-in> complains that it is being passed an input of the wrong type. Is there a way to detect whether this form variable is a list or string? Using the len function doesn't work because len works on both strings and lists.
You need the python 'type' statement, which unfortunately isn't available to python scripts (its use is restricted). Therefore, you need a small external method: def typeof(self,a,b): if type(a) == type(b): return 1 else: return 0 Then to use this method you can: <dtml-call "REQUEST.set('a', [])"> <dtml-call "REQUEST.set('b', 'abc')"> <dtml-if "typeof(a,[])"> a is a list<br> </dtml-if> <dtml-if "typeof(b,'')"> b is a string<br> </dtml-if> Note: in the second dtml-if above, you are checking 'b' against an empty string (two single quotes) If you run the above dtml you will get: a is a list b is a string HTH Jonathan
On Wed, Sep 22, 2004 at 03:21:21PM -0400, Jonathan Hobbs wrote:
----- Original Message ----- From: "Asad Habib" <ahabib@engin.umich.edu>
I have a form variable whose value is being passed to a DTML method upon form submission. In this DTML method, I use the form variable as input to a <dtml-in>. When this form variable is passed as a list(i.e. it contains multiple values), everything works fine. However, when this form variable is passed as a string(i.e. it contains a single value), <dtml-in> complains that it is being passed an input of the wrong type. Is there a way to detect whether this form variable is a list or string? Using the len function doesn't work because len works on both strings and lists.
You need the python 'type' statement, which unfortunately isn't available to python scripts (its use is restricted). Therefore, you need a small external method:
What's wrong with same_type which zope provides for this purpose? -- Paul Winkler http://www.slinkp.com
----- Original Message ----- From: "Paul Winkler" <pw_lists@slinkp.com>
----- Original Message ----- From: "Asad Habib" <ahabib@engin.umich.edu>
I have a form variable whose value is being passed to a DTML method
upon
form submission. In this DTML method, I use the form variable as input to a <dtml-in>. When this form variable is passed as a list(i.e. it contains multiple values), everything works fine. However, when this form variable is passed as a string(i.e. it contains a single value), <dtml-in> complains that it is being passed an input of the wrong type. Is there a way to detect whether this form variable is a list or string? Using the len function doesn't work because len works on both strings and lists.
You need the python 'type' statement, which unfortunately isn't available to python scripts (its use is restricted). Therefore, you need a small external method:
What's wrong with same_type which zope provides for this purpose?
I've been using my 'typeof' external method for about 100 years - it feels that long :), but I like the new (new-to-me!) same_type function!
participants (3)
-
Asad Habib -
Jonathan Hobbs -
Paul Winkler