I have tried a few methods to get this to work, but to no avail. I
hope I can get some help with this.

**********
The long version:
When a user is logged in and loads a page (containing a reply form at
the bottom), he is able to type in his reply.

Presuming he takes very long to type the reply and his session expires
(logged out from inactivity), and he hits "submit", I would like to
check if his session is still alive before form submission (or on
validation), and notify him if his session expired (and don't submit
the form!)

**********
Briefly:
- Form on the page requires user to be logged in.
- On form submit, check that user is still logged in before processing
form.
- If user was accidentally logged out (or session expired), flash a
message that "your session has expired" and stay on the same page
(don't submit form).

**********
I have tried:
- SQLFORM(db.table, _onsubmit=validate_session())
- form.process(onvalidation=validate_session())

Both methods seemed to have been bypassed (??). My code without the
validation methods:
def show_form():
  if auth.is_logged_in():
    form = SQLFORM(db.table)
    if form.process().accepted:
      response.flash = 'Reply Successful'
    elif form.errors:
      response.flash = 'Reply has errors'
  else:
    form = auth.login()
return dict(form=form)

Reply via email to