On Dec 1, 11:53 pm, Anthony <[email protected]> wrote:
> On Thursday, December 1, 2011 10:37:20 AM UTC-5, lyn2py wrote:
>
> > Reply below
>
> > On Dec 1, 11:15 pm, Anthony <[email protected]> wrote:
> > > When the form is submitted, your function first checks if the user is
> > > logged in -- if not, it never gets to the code that creates or processes
> > > the form, so of course it can't execute your onvalidation function. Also,
>
> > I think you just hit the nail. How can I intercept the process?
>
> You could check for login after creating the form but before processing it,
> and if not logged in, still return the form, with the flash message.
I appreciate your guidance and assistance (a website? code examples?)
to do this. Thank you!
> > > 'onvalidation' should be a function, not a call to a function (i.e., just
> > > validate_session, not validate_session()).
>
> > I used validate_session initially and it gave me an error...
> > >> TypeError: validate_session() takes no arguments (1 given)
> > so I added the (), no error. *puzzled*
>
> An onvalidation function takes the form itself as an argument, so you have
> to define a function that takes a form as an argument.
Thank you for clarifying. I understand it now!
> > > Also, note that adding an "_onsubmit" attribute to SQLFORM will end up
> > > adding an "onsubmit" attribute to the HTML <form> tag, so the value of
> > that
> > > attribute should be a Javascript string to be executed on the client
> > side,
> > > not a Python function. In that case, it should trigger an Ajax callback
> > to
> > > check login status, and the resulting behavior will have to be handled
> > > client side (either flashing the message or proceeding with submitting
> > the
> > > form).
>
> > I used a simple Javascript function for this:
> > <script type="text/javascript">
> > <!--
> > function validate_session(){
> > return false
> > }
> > //-->
> > </script>
>
> > It works when the user is logged in (nothing is submitted)
> > But it fails when the user session expires
>
> But the above will never let the form submit because it doesn't actually
> check if the user is logged in -- it just stops the submission in every
> case. Instead, the function would have to make an Ajax call to the server
> to check for login, and depending on the returned result, it would either
> submit the form or prevent submission and flash a message.
Yup.