i need some help on adding custom error messages to the form fields. i
have a signup form:
class SigninFields(WidgetsList):
email =
forms.TextField(validator=forms.validators.Email(not_empty=True))
password =
forms.PasswordField(validator=forms.validators.NotEmpty)
signin_form = forms.TableForm(fields=SigninFields(), action="login")
in my controller, i use @validate decorator so in case of invalid
input it handles them, not me.
now, after the initial validation check i have to check if there is
any users with the given email and password. if not, i want to raise
an Invalid exception and i want to display it next to the "email"
field where normally it would display the "please enter a value" error
message.
thanks in advance.
thanks again.
@expose('app.templates.users.signin')
def signin(self, email=None, password=None):
if tmpl_context.form_errors.has_key('_the_form'):
tmpl_context.signin_form =
signin_form(error=tmpl_context.validation_exception)
else:
tmpl_context.signin_form = signin_form()
return dict()
@expose()
@validate(signin_form, error_handler=signin)
def login(self, email, password):
password = md5(password).hexdigest()
user =
self.user_service.get_user_by_email_and_password(email=email,
password=password)
if not user:
raise Invalid('No user matched with the given info',
email, None,
error_dict={'email': 'No user matched with the
given info.'})
session["user_id"] = user.id
session["name"] = "%s %s" % (user.firstname, user.lastname)
session["usergroup_id"] = user.usergroup_id
session.save()
> --
> You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group.
> To post to this group, send email to toscawidge...@googlegroups.com.
> To unsubscribe from this group, send email to toscawidgets-dis...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/toscawidgets-discuss?hl=en.
>