I am replacing:
form=crud.update(table=db.aboutText,hidden=dict(nodeID=id,aboutID=aboutID),record=row,next=session.crud_next,onaccept=onaccept_about_text,deletable=True)
crud.messages.record_updated=session.record_updated
crud.messages.record_deleted=session.record_deleted
crud.messages.record_created=session.record_updated
With functions using SQLFORM:
def onaccept_about_text(form):
del session.name
del session.aboutID
def generic_about():
name=session.name
aboutID=session.aboutID
record=db((db.aboutText.nodeID==id)&(db.aboutText.aboutID==aboutID)).select(db.aboutText.ALL).first()
form=SQLFORM(table=db.aboutText,record=record,deletable=True,showid=False,separator='',hidden=dict(nodeID=id,aboutID=aboutID))
if form.process(onsuccess=lambda form:
onaccept_about_text(form),next=session.crud_next).accepted:
session.flash='Form accepted'
elif form.errors:
response.flash='Form has errors'
else:
response.flash='Please fill out the form'
return dict(form=form)
I am struggling with the flash messages. When I display the form the flash
is correctly set to: 'Please fill out the form', also when the form
contains errors the message is set to: 'Form has errors'. However, when the
form is accepted, no flash message is being displayed. When I remove the
onsuccess= lambda form: onaccept_about_text(form) from process() the flash
message does display not 'Form accepted' but 'Success!'
How do I set the flash message correctly. Furthermore, I'd like the flash
messages to distinguish between inserting/updating/deleting a record, is
that possible?
Since web2py sets the flash message to 'Success!' and 'Errors in form,
please check it out' I only need to set 'Please fill out the form',
however,
form=SQLFORM(...)
if form.process(..).accepted:
cannot be empty, I could move the redirect from process() to the if, but
that would be a workaround. What's the correct way to use SQLFORM here?
Kind regards,
Annet
--