Hello,

In the book there is this example :

db.define_table('numbers',
    Field('a', 'integer'),
    Field('b', 'integer'),
    Field('c', 'integer', readable=False, writable=False))

def my_form_processing(form):
    c = form.vars.a * form.vars.b
    if c < 0:
       form.errors.b = 'a*b cannot be negative'
    else:
       form.vars.c = c

def insert_numbers():
   form = SQLFORM(db.numbers)
   if form.process(onvalidation=my_form_processing).accepted:
       session.flash = 'record inserted'
       redirect(URL())
   return dict(form=form)


Where "my_form_processing" function is called without bracket and
arguments...

I try to do this that failed :

def my_form_processing(table_name, form):
    form.vars.field1 = table_name # I know useless, it just
demonstration for purpose of my question...

...

 if form.process(onvalidation=my_form_processing(request.args(0),
form)).accepted:

Then I did :

def my_form_processing(form):
    form.vars.field1 = request.args(0)

...

 if form.process(onvalidation=my_form_processing).accepted:

That actually works...

I would like to make sure that I understand onvalidation properly...

Is "my_form_processing" just a extension of the "insert_numbers()"
function?

And if so, does it have access to all the same variables
(environnement) of "inser_numbers()"??

Thank you!

Richard


Reply via email to