[Zope] Newbie: help with math syntax?

Jeffrey Shell Jeffrey@digicool.com
Thu, 16 Sep 1999 15:30:32 -0400


> Code for index_html
> 
> 
> <!--#var standard_html_header-->
[snip!]
> 
> <FORM ACTION="addTotal">
> <P>Enter a number:
> <INPUT TYPE="text" SIZE="3" NAME="number1"></P>
> <P>Enter a number:
> <INPUT TYPE="text" SIZE="3" NAME="number2"></P>
> <P>Enter a number:
> <INPUT TYPE="text" SIZE="3" NAME="number3"></P>
> 
> <INPUT TYPE="submit" VALUE="Compute">
> </FORM>

Zope (the ZPublisher part of it actually) has a really powerful feature
here to marshal form values into the right sort of objects.  In this
case, you probably want integers or floats.  Instead of: NAME="number1",
try NAME="number1:int" or NAME="number1:float" (you may want to put
default values of zero in these fields as well).  When the form is
submitted, the value for 'number1' will be an integer or float object,
which you can then do math on, like thus:

The total is: 
<!--#var expr="number1+number2+number3"--><BR>

For doing square roots, it _might_ be something like

<!--#var expr="_.math.sqrt(number1)"-->

Behold the power of the new www.zope.org site and the documentation and
how-to's it contains, as well as the Zope Quick Reference.  They'll have
more information on this.