[Zope] Incrementing a form field

César A. K. Grossmann ckant@fazenda.gov.br
Mon, 11 Dec 2000 16:44:32 -0200


Hi!

I have a form that is used to insert some records to a database, and one
of the fields is a sequence number. I want to increment this number when
the form is used, unless is the first time it is loaded.

The form (idea copied from the SmartForms HOWTO) have the name
"Register", and is something like this:

<dtml-var standard_html_header>

<dtml-if "REQUEST.REQUEST_METHOD=='POST'">
  Record inserted.
</dtml-if>

<dtml-if my_number>
  <dtml-call "REQUEST.set('my_number', my_number + 1)">
<dtml-else>
  <dtml-call "REQUEST.set('my_number', 1)">
</dtml-if>

<form action="Register" method="POST">
A Field <input name="my_field" value="some value"><br>
A Number <input name="my_number" value="<dtml-var my_number>"><br>
<input type="submit" value="OK">
</form>

<dtml-var standard_html_footer>

It work for the first load, but when I press the OK button, I get an
error message:

Error Type: TypeError
Error Value: illegal argument type for built-in operation

The traceback:

<!--
Traceback (innermost last):
  File /usr/lib/python1.5/site-packages/ZPublisher/Publish.py, line 222,
in publish_module
  File /usr/lib/python1.5/site-packages/ZPublisher/Publish.py, line 187,
in publish
  File /usr/share/zope/lib/python/Zope/__init__.py, line 221, in
zpublisher_exception_hook
    (Object: Traversable)
  File /usr/lib/python1.5/site-packages/ZPublisher/Publish.py, line 171,
in publish
  File /usr/lib/python1.5/site-packages/ZPublisher/mapply.py, line 160,
in mapply
    (Object: Register)
  File /usr/lib/python1.5/site-packages/ZPublisher/Publish.py, line 112,
in call_object
    (Object: Register)
  File /usr/share/zope/lib/python/OFS/DTMLMethod.py, line 172, in
__call__
    (Object: Register)
  File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_String.py,
line 528, in __call__
    (Object: Register)
  File /usr/lib/python1.5/site-packages/DocumentTemplate/DT_Util.py,
line 342, in eval
    (Object: REQUEST.set('my_number', my_number + 1))
    (Info: REQUEST)
  File <string>, line 0, in ?
TypeError: (see above)

-->

What is wrong? How do I increment the value?

[]s
-- 
 +---------------------------------+---------------------------------+
 | César A. K. Grossmann           | Capacitação Solidária           |
 | ckant@fazenda.gov.br            | http://www.uol.com.br/umminuto/ |
 | http://members.xoom.com/ckant/  | Clique e doe - é de graça       |
 +---------------------------------+---------------------------------+
       http://www.halcyon.com/sciclub/cgi-pvt/instr/instr.html
  A ética do iG: http://antispambr.abranetrj.org.br/not-20001023.html

One Bell System - it used to work before they installed the Dimension!