Search code examples
formsvalidationweb2py

web2py form with DB check


I'm using web2py forms, but I need to set up a limit for 20 users registration. How can I do it?

PS: Edit to make easy to understand Thanks in advance. Best regards!


Solution

  • Assuming you wish to limit registration to a maximum of 20 users and you are using the standard /default/user function from the scaffolding application:

    In the default.py controller:

    def user():
        if request.args(0) == 'register' and db.auth_user.count() >= 20:
            form = None
        else:
            form = auth()
        return dict(form=form)
    

    In the default/user.html view:

    {{if form is None:}}
    <p>Sorry, no more registrations allowed.</p>
    {{else:}}
    {{=form}}
    {{pass}}