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]'],
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:
responce.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?
>>
>
--