Thanks for explanation... But I am unable to do what you explain because I try to make a kind of virtual table to form submission... So I need the "virtual table name" I pass by request.args(0) to access some dict that I build to make my virtual table to work...
May I request "request.args(0)" form "my_form_processing" if the only thing "my_form_processing" get is the form? It works once, but I think it not working every time. I mean I get my own "my_form_processing" function to works with request.args(0), but it not seems to work anymore after restart web2py (local dev with rocket built-in server). Thanks Richard On Fri, Dec 23, 2011 at 4:13 PM, Massimo Di Pierro < massimo.dipie...@gmail.com> wrote: > onvalidation = my_form_processing > > registers a callback (called after validation and before accepting). > This does not work > > def my_form_processing(table_name, form): form.vars.field1 = > table_name # I know useless, it just > > because the callback function must take a single parameter, the form. > You can do instead > > def my_form_processing(form): > form.vars.field1 = form.table.name # I know useless, it just > > Hope this helps. > > > On Dec 23, 1:32 pm, Richard <ml.richard.vez...@gmail.com> wrote: > > 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 >