Forms with error reporting

10 views
Skip to first unread message

Hawkeye

unread,
Sep 12, 2006, 12:12:14 AM9/12/06
to Django users
The FormWrapper design pattern seems to be great, but I have a
question.

Is there any way that I can put errors in the response that aren't
linked with form fields?

For example, in an authentication page... if the authentication fails,
I don't want to link an error to either the user or password field...
it should be linked to the page. I guess what I'm looking for is
something like 'form.generic.errors'

Thanks in advance,
--Ben

rp

unread,
Sep 12, 2006, 2:01:05 PM9/12/06
to Django users
You can use the manipulators described on this page:

http://www.djangoproject.com/documentation/forms/

Do a find on "if form.has_errors" to see a template example
containing general form errors as well as field specific
form errors.

Let me know if you need more info.

thanks,

raman

Hawkeye

unread,
Sep 12, 2006, 5:16:31 PM9/12/06
to Django users
The example shows only field-specific errors...

==========
{% if form.has_errors %}
<h2>Please correct the following error{{ form.error_dict|pluralize
}}:</h2>
{% endif %}
...
{% if form.name.errors %}*** {{ form.name.errors|join:", " }}{% endif
%}
==========

As I understand it, this block is only determining if there are errors
on the page and if there are one or many. Then it progresses into
per-field errors.

I'm looking more for:
==========
{% if form.has_errors %}
<h2>Please correct the following error{{ form.error_dict|pluralize
}}:</h2>
{% if form.generic.errors %}*** {{ form.generic.errors|join:", " }}{%
endif %}
{% endif %}
...
==========

I could do this by defining a 'generic' field and manually assigning
errors to it, but that seems like a kludge.

Thanks for your feedback so far,
--Ben

Waylan Limberg

unread,
Sep 13, 2006, 10:49:28 AM9/13/06
to django...@googlegroups.com
On 9/12/06, Hawkeye <google...@bit24.net> wrote:
>
> The FormWrapper design pattern seems to be great, but I have a
> question.
>
> Is there any way that I can put errors in the response that aren't
> linked with form fields?
>

There is currently a discussion[1] going on in the dev-list regarding
a proposal for reworking form validation. I don't recall if such a
thing was part of the proposal, but now's the time to add your input.

[1]: http://groups.google.com/group/django-developers/browse_thread/thread/7eceb616b251cbd0/

--
----
Waylan Limberg
way...@gmail.com

Reply all
Reply to author
Forward
0 new messages