[Zope] ids NameError

J Cameron Cooper jccooper at jcameroncooper.com
Tue Aug 26 19:37:29 EDT 2003


>I have a dtml form that itterates over the content of a
>folder and displays a checkbox next to each of the files.
>The form allows a user to select items to be deleted. If a
>user does not select a check box I get the folloewing
>error:
>
>Error Type: NameError
>Error Value: global name 'ids' is not defined
>
>This only happens when a checkbox has not been selected.
>
>here is the form calling a method:
>
><FORM ACTION="delete" method="POST">
><dtml-in "objectValues(['File'])" sort=id>
><INPUT TYPE="CHECKBOX" NAME="ids:list" VALUE="<dtml-var
>id>"> <dtml-var id><p>
></dtml-in>
><INPUT TYPE="SUBMIT">
></form>
>  
>
When you do an HTTP POST or GET a form parameter is only sent for a 
checkbox if that checkbox is checked. Nothing is done if it is 
unchecked. Yes, this is a little silly, but we have to deal with it. In 
any case, you can never rely on a request from a web environment to be 
well-formed.

You need to check in the destination script ('delete') for existence of 
'ids', and do the appropriate thing if it does not exist. This may be as 
simple as::

if not ids:
  ids = []

Or maybe you have different logic if there's no contents. Since you're 
deleting from a list (presumably) you can probably just skip the whole 
part where you delete things.

          --jcc





More information about the Zope mailing list