By default, .validate doesn't do a database insert (which is why you have manually done the insert yourself after calling .validate), so obviously there will be no form.vars.id at the point that the onsuccess callback is called. If you need the id available in the callback, then either use .process or call .validate(..., dbio=True).
Anthony On Monday, April 6, 2015 at 4:23:17 PM UTC-4, 黄祥 wrote: > > why the result in form.process and in form.validate is different? > e.g. > *modules/test_event.py* > def oncreate_event(form): > current.db.auth_event.insert(time_stamp = current.request.now, client_ip = > current.request.client, > user_id = current.auth.user_id, origin = '%s/%s' % > (current.request.controller, current.request.function), > description = 'ID %s created' % (form.vars.id) ) > > *controlelrs/default.py* > """ cutted """ > if form.validate(onsuccess = test_event.oncreate_event): > db.purchase_header.insert(**dict(form.vars) ) > #test_event.oncreate_event(form) > > *result * > when user input new record, it also recorded in auth_event but > form.vars.id is not passed when using form.validate, yet using > form.process().accepted can work fine > > any idea how to handle this in web2py way? > > thanks and best regards, > stifan > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.