Thanks for the help. I'll modify my code accordingly.

On Jan 14, 6:27 am, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Thursday, January 13, 2011 7:30:56 PM UTC, hank23 wrote:
>
> > I have a screen which displays just fine the first time in, however
> > when I knowingly submit the page without entering data in all of the
> > fields to cause an error the page loses some of the data and controls.
> > I'm sure my view code is probably missing something just not sure at
> > this point what exactly is missing. So far my view is coded according
> > to the example given in the document at
> >http://docs.djangoprojects.com/en/1.2/topics/forms/.
> > The example though does not seem to clearly indicate what should be
> > sent back to the screen in the case of errors. Below is my addchoice
> > view which is the one in question:
>
> > <snip>
>
> > I would appreciate any suggestions for how to correc the code or links
> > to one or more complete screen error processing view code. Thanks for
> > the help.
>
> You need to think about the path through the code that happens when
> request.method is POST, but the form is not valid. In that case, in your
> current code, dctnry is empty, so does not pass the form back to the
> template.
>
> Since you want to modify the contents of dctnry when the form is saved, I
> would do it like this:
>
>     dctnry = {'infomessage': message}
>
>     if request.method == "POST":
>         form = AddChoiceForm(request.POST)
>         if form.is_valid():
>             poll = form.cleaned_data['pollquestions']
>             slctdchoice = form.cleaned_data['newchoice']
>             if poll:
>                 newchoice = Choice(poll=poll.id,
> choice=slctdchoice, votes=0)
>                 newchoice.save()
>                 confirmmessage = "Choice: %s has been saved for poll: %s" %
> (slctdchoice, pollid)
>                 dctnry['confirmmessage'] = confirmmessage
>
>     else:
>         form = AddChoiceForm()
>
>     dctnry['form'] = form
>     return render_to_response('polls/addchoice.html' dctnry,
>                      context_instance=RequestContext(request))
>
> which ensures that the form is always added to the context, no matter where
> it is instantiated.
> --
> DR.- Hide quoted text -
>
> - Show quoted text -

-- 
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