to add to massimo's response, i have added some HTML5'ness to my 
registration widget:

        reg_form = auth.register()
        reg_form.custom.widget.email['_required'] = True
        reg_form.custom.widget.stage_name['_required'] = True
        reg_form.custom.widget.stage_name['_pattern'] = '[\w-]{3,20}'
        reg_form.custom.widget.stage_name['_title'] = 'Choose a stagename 
of 3-20 characters'
        reg_form.custom.widget.password['_required'] = True
        reg_form.custom.widget.password_two['_required'] = True

good luck!

cfh

On Monday, July 16, 2012 1:50:45 PM UTC-7, Massimo Di Pierro wrote:
>
> 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! 
>>
>>
>>
>>

-- 



Reply via email to