For "creation" forms (forms that not update an existing record but insert a new one) you do not know the id in advance. onvalidation is called before the record is inserted, and is meant to report any errors that standard validators do not cover.
Your function is called a moment before the record is inserted, and web2py does not (yet) know what will be the the id of it. That's because if your function "fills" form.errors: a) the record would be discarded b) the page will return the form with the corresponding errors On Saturday, August 25, 2012 8:57:55 PM UTC+2, pylix wrote: > > > fixed a typo > > On Saturday, August 25, 2012 2:52:17 PM UTC-4, pylix wrote: >> >> the problem i found after debugging is this... >> here's the some code in the model >> >> def build_email(form): >> html_email = '<html>%s</html>' % BEAUTIFY(form.vars) >> mail.send(to=['[email protected] <javascript:>'], >> reply_to=form.vars.email, >> subject='request' + str(form.vars.id), >> message=html_email) >> session.id = form.vars.id >> >> def freequote(): >> form = SQLFORM(db.person) >> if form.process(onvalidation=build_email).accepted: >> redirect(URL(quotesuccess)) >> else: >> response.flash = 'errors found' >> return dict(form=form) >> >> the problem i see is that before the form is accepted, >> "id" does not exist, while all the other fields can >> be accessed with form.vars.field, in the code above >> form.vars.id = None so the email subject would >> be requestNone. >> >> when the onvalidation function is omitted >> and instead the freequote controller directly calls the function after >> the form is processed, form.vars.id works as expected >> >> I misinterpreted the purpose of onvalidation >> i'd like to send emails after not before forms >> are validated so i have no more issues. >> >> but this all leads me to the realization that web2py does >> not give a value to the form field of a SQLFORM until the form >> is processed, is there a request.vars.id that can >> be used before processing? >> >> >> >> >> On Saturday, August 25, 2012 9:43:48 AM UTC-4, Anthony wrote: >>> >>> Can you show your code? It should be in form.vars.id after submission. >>> >>> Anthony >>> >>> On Saturday, August 25, 2012 9:16:42 AM UTC-4, pylix wrote: >>>> >>>> I'm having trouble getting the server to access the id field upon >>>> submission of my SQLFORM >>>> I did not define my own id field in the model, i have no issue with the >>>> auto-created one except that >>>> I can't figure out how to store the id in a variable for view use. >>>> >>>> all other fields are accessible using forms.vars i.e form.vars.name, >>>> form.vars.email, etc.. >>>> but form.vars.id always ends up as None. >>>> >>>> The id field values are recorded and can be queried >>>> or viewed using appadmin database administration >>>> but, what I'm trying to do is use the Id# in a view that >>>> i want to display after form submission. >>>> >>>> is there a special way to get the id# that the >>>> record being inserted to database would be >>>> if it validates? >>>> >>> --

