When I do this:
form=SQLFORM.factory(
Field('your_email',requires=IS_EMAIL()),
Field('your_phone'),
Field('subject'),
Field('question', 'text', requires=IS_NOT_EMPTY()))
form.vars = dict(subject='Item %s: %s' % (database.id, database.title))
if form.process().accepted:
if mail.send(to='[email protected]',
subject='Regarding %s' % form.vars.subject,
message='From %s at %s: %s' % (form.vars.your_email,
form.vars.your_phone, form.vars.question)):
response.flash='Your message has been sent! We will contact you
shortly.'
elif form.errors:
form.errors.your_email='Unable to send email'
return dict(equipment=equipment, form=form)
I get this error:
Traceback (most recent call last):
File "/home/james/web2py/gluon/restricted.py", line 205, in restricted
exec ccode in environment
File "/home/james/web2py/applications/equipment/controllers/default.py"
<http://127.0.0.1:8000/admin/edit/equipment/controllers/default.py>, line 309,
in <module>
File "/home/james/web2py/gluon/globals.py", line 173, in <lambda>
self._caller = lambda f: f()
File "/home/james/web2py/applications/equipment/controllers/default.py"
<http://127.0.0.1:8000/admin/edit/equipment/controllers/default.py>, line 179,
in details
if form.process().accepted:
File "/home/james/web2py/gluon/html.py", line 1994, in process
self.validate(**kwargs)
File "/home/james/web2py/gluon/html.py", line 1941, in validate
if self.accepts(**kwargs):
File "/home/james/web2py/gluon/sqlhtml.py", line 1274, in accepts
self.vars.id = self.table.insert(**fields)
AttributeError: 'dict' object has no attribute 'id'
PS: What is the best way to provide a condition in case mail sending fails?
--