Well thats what i was complaining about in the beginning that i could
use good example of how to do it. Its quite confusing how form
validation is on one page, errors on the others and views on third and
there is not single full example.

How should the else part be?

else:
    message = "form was not valid"
    accform = form
    ...
    return render_to_response......

something like that perhaps?

Alan

On Jun 9, 12:23 am, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Jun 8, 2009 at 3:57 PM, zayatzz <alan.kesselm...@gmail.com> wrote:
>
> > Well now this is working just fine:
>
> > [snip AccountForm]
>
> > But this (code below) still does not return me any error messages from
> > form validation.
>
> >                form = AccountForm(request.POST)
> >                user = request.user
> >                if form.is_valid():
> >                        do stuff and save user.
> >                else:
> >                        initial_dict = {
> >                                'username': user.username,
> >                                'email': user.email,
> >                                'first_name':user.first_name,
> >                                'last_name':user.last_name,
> >                        }
> >                        message = "was not valid"
> >                        accform = AccountForm(initial=initial_dict)
> >                        proform = ProfileForm()
> >                        context = { 'message':message, 'aform':accform,
> > 'pform':proform, }
> >                        return
> > render_to_response('profile/profile_detail.html', context,
> > context_instance=RequestContext(request))
>
> > Any idea why?
>
> The errors are stored in the form instance you create from the POST data and
> call is_valid() on. In the case where is_valid() returns False you are
> creating an entirely new (unbound) AccountForm with initial data and passing
> that to the template.  You aren't passing in the form instance that failed
> validation, so the template cannot report the errors.  That whole else block
> looks more like it belongs to the GET processing case, not the
> POST-but-form-failed-validation case.
>
> Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to