mdipierro/web2py — pull request #32 by ldhughes (2012-12-12 20:17:19+00:00)
Title: Add onfailure parameter to form.grid.

Add _onfailure_ parameter to _form.grid_ to permit running code when a validation failure occurs.

``` Python
def on_validate(form):
if not auth.has_membership(role='Admin'):
argv = len(request.args)
edit = True
user_id = '0'
if argv % 2:
edit = False
if argv in [5,6]:
# auth_membership
user_id = request.args[2]
elif argv in [3,4]:
# auth_user
if edit:
user_id = request.args[3]
if user_id != '0':
# Not adding user
message = 'Insufficient privileges to %s an Admin user'
if auth.has_membership(user_id=user_id, role='Admin'):
form.errors.error = message % 'edit'
else:
if form.vars.group_id == str(auth.id_group('Admin')):
form.errors.error = message % 'add'
return

def on_failure(form):
response.flash=form.errors.error
```