I've been working around this issue for literally years and finally have the time to seek a real solution. :) I can't find much information, so I'm assuming I'm just taking the wrong approach. Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there? Most of my forms have optional fields and this is especially painful when trying to use ZSQL Methods or when creating multipage forms that refer to earlier form values. Any suggestions would be greatly appreciated!! Thanks, Dave
David Ayres wrote:
I've been working around this issue for literally years and finally have the time to seek a real solution. :) I can't find much information, so I'm assuming I'm just taking the wrong approach.
Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there?
Most of my forms have optional fields and this is especially painful when trying to use ZSQL Methods or when creating multipage forms that refer to earlier form values.
The specifications for forms only require certain "successful" controls to be submitted, and most browsers work this way. This is specially noticable with checkboxes, which when on are in the request and absent when off. See: http://www.w3.org/TR/REC-html40/interact/forms.html#successful-controls Frankly, I consider this behavior bizarre and unhelpful, but there's not much to be done about it protocol-side. I would imagine there's a hstorical reason. For use in Zope, keep in mind that parameters for both Python scripts and Z SQL Methods allow for default values, so you don't have to rely on a parameter being present in the request. In ZPTs there's conditional expressions, and in DTML the 'missing' pseudo-attribute. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com
Thanks for the information. I have been pulling my hair out because I have some lengthy forms (wizards) and it can be harrowing at times. :) I think the best solution for my situation is to do a JS/CSS tabbed solution, so it's one form. Are you aware of any limitations on the size of posted data? I haven't hit any "walls" yet with respect to that. Dave -----Original Message----- From: J Cameron Cooper [mailto:zope-l@jcameroncooper.com] Sent: Wednesday, June 15, 2005 12:05 PM To: David Ayres Cc: zope@zope.org Subject: Re: [Zope] Form Variables David Ayres wrote:
I've been working around this issue for literally years and finally have the time to seek a real solution. :) I can't find much information, so I'm assuming I'm just taking the wrong approach.
Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there?
Most of my forms have optional fields and this is especially painful when trying to use ZSQL Methods or when creating multipage forms that refer to earlier form values.
The specifications for forms only require certain "successful" controls to be submitted, and most browsers work this way. This is specially noticable with checkboxes, which when on are in the request and absent when off. See: http://www.w3.org/TR/REC-html40/interact/forms.html#successful-controls Frankly, I consider this behavior bizarre and unhelpful, but there's not much to be done about it protocol-side. I would imagine there's a hstorical reason. For use in Zope, keep in mind that parameters for both Python scripts and Z SQL Methods allow for default values, so you don't have to rely on a parameter being present in the request. In ZPTs there's conditional expressions, and in DTML the 'missing' pseudo-attribute. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com
David Ayres wrote:
Thanks for the information. I have been pulling my hair out because I have some lengthy forms (wizards) and it can be harrowing at times. :) I think the best solution for my situation is to do a JS/CSS tabbed solution, so it's one form. Are you aware of any limitations on the size of posted data? I haven't hit any "walls" yet with respect to that.
I don't think there are any. I know I've posted files over .5Gb in size, probably bigger. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 J Cameron Cooper wrote:
David Ayres wrote:
I've been working around this issue for literally years and finally have the time to seek a real solution. :) I can't find much information, so I'm assuming I'm just taking the wrong approach.
Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there?
Most of my forms have optional fields and this is especially painful when trying to use ZSQL Methods or when creating multipage forms that refer to earlier form values.
The specifications for forms only require certain "successful" controls to be submitted, and most browsers work this way. This is specially noticable with checkboxes, which when on are in the request and absent when off. See:
http://www.w3.org/TR/REC-html40/interact/forms.html#successful-controls
Frankly, I consider this behavior bizarre and unhelpful, but there's not much to be done about it protocol-side. I would imagine there's a hstorical reason.
I would be willing to bet (a small amount ;) that the rationale was to do with conserving bandwidth: a classic "penny wise, pound foolish" error. Because "hidden" form elements are always submitted, Zope offers a pattern for dealing with this, most often used with checkboxes: <form action="process_form_submission" method="POST"> ... <input type="hidden" name="possibly_missing:default:int" value="0" /> <input type="checkbox" name="possibly_mission:boolean" value="1" /> ... </form> This pattern guarantees that the field will be present in the REQUEST.form dict: the publisher uses the '...:default' value only if no other value for that name is present, and strips of the ':default' suffix during field conversion. Tres. - -- =================================================================== Tres Seaver +1 202-558-7113 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCsG8w+gerLs4ltQ4RAgtdAKDNsfY13APRfMb/IE1YdiOeuFj/ygCeOm59 RRem3eY4OAkiw34Oe+TPjqM= =ZXs+ -----END PGP SIGNATURE-----
Am Mittwoch, den 15.06.2005, 11:27 -0400 schrieb David Ayres:
I've been working around this issue for literally years and finally have the time to seek a real solution. :) I can't find much information, so I'm assuming I'm just taking the wrong approach.
Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there?
Most of my forms have optional fields and this is especially painful when trying to use ZSQL Methods or when creating multipage forms that refer to earlier form values.
Any suggestions would be greatly appreciated!!
Zope has along with nice type converters, also a workaround for the checkbox-problem: http://www.zope.org/Members/Zen/howto/FormVariableTypes However, working with request.form.get('value',default) is often more robust.
David Ayres wrote at 2005-6-15 11:27 -0400:
Whenever a form is posted, the text fields always show up in the request.form, however any other type of form element that has not been given a value does not show up. None of the fields have the ignore_empty attribute. Besides using the missing= attribute, what other options are there?
This is as specified by HTML: Unchecked check boxes and not selected options are not sent by the browser. Zope allows you to use suffixes to tell its ZPublisher component to hande form variables in a special way. One of these suffixes is ":default". It is used in an '<input type=hidden name="variable:default" value="some_value">' to provide a default value for "variable". You find a discription of more of these magic suffixes in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> -- Dieter
participants (5)
-
David Ayres -
Dieter Maurer -
J Cameron Cooper -
Tino Wildenhain -
Tres Seaver