The register function, as all the functions in auch which return a form,
call process internally. Therefore if you fo
form = auth.register()
form.process()
you would be calling process twice with undesired consequences. Moreover if
the process() called inside it successful and the form was accepted you may
have a redirect (raise HTTP) and therefore the function never returns.
I think this is what you want:
def register():
def onvalidation(form):
if form.errors: # form has errors
session.flash = 'Registration form processed, please check your
email'
def onaccept(form): # form accepted
response.flash = 'Registration form contains error(s)'
auth.settings.register_onvalidation.append(onvalidation)
auth.settings.register_onaccept.append(onaccept)
form = auth.register()
if not form.vars: # form not sumitted
response.flash = 'Please fill in the registration form'
return dict(form=form)
Anyway if all you want is set errors, you should use auth.messages.*
2.
open a web2py shell with
python web2py.py -S welcome -M -N
then experiment yourself
form = auth.register()
print form
form['_class'] = 'test'
print form
form.element('input[name=myfield]')['_class'] = 'test' # jquery syntax
print form
On Monday, 16 July 2012 13:30:06 UTC-5, cyan wrote:
>
>
> I have a couple of questions about the provided Auth.register() function
> (I suppose they also apply to other Auth functions in general):
>
> 1. In a controller, if I do:
>
> def register():
> return dict(form=auth.register())
>
> with the following settings in a model:
>
> auth.settings.registration_requires_verification = True
> auth.settings.register_next = URL (...)
>
> Everything works as expected, i.e. the verification email is sent after
> the registration form is processed, and the user gets re-directed to a
> different page. However, as soon as I do sth like:
>
> def register():
> form = auth.register()
>
> if form.process().accepted:
> session.flash = 'Registration form processed, please check your
> email'
> elif form.errors:
> response.flash = 'Registration form contains error(s)'
> else:
> response.flash = 'Please fill in the registration form'
>
> return dict(form=form)
>
> *Both verification email and re-direction stop working even though the
> form processed successfully* (a record is inserted, the form clears
> itself, and a flash message 'Success!' appears). I wonder what causes this
> breakdown? I am using the trunk version of web2py.
>
>
> 2. How much customization can we do with the form returned by
> auth.register()? I know we can add add fields to it (a few different ways),
> but there are many other things one may want to adjust. For example, I am
> able to do sth like:
>
> form.element(_type='submit')['_class'] = '...'
>
> to change the class of its elements. How do we change the class for the
> whole form? How do we change the label for each field? How do we adjust the
> position of each field? How do we position the whole form on the page? etc.
>
> Thanks in advance!
>
>
>
>
--