im having some trouble with displaying form errors within one view. I'm currently a student and have been taking python classes for 2 semesters. I decided to learn some Django on my own.
The issue that i have come across is that im trying to have a multistep process so a user can post a book. But, i want to do it within the same url. so when the user finishes the first form and clicks submit it will go on to the next form but the url wont change. I have figured this out. my issues is that when i get to the second form there are form errors already displaying that appear along with the form. I spend like 3 hours yesterday trying to figure out and no luck. so if anyone can give a helping hand that would be great! thanks!
def book_post(request):
if request.method == 'POST':
formone = bookFormOne(request.POST)
formtwo = bookFormTwo(request.POST, request.FILES)
if formtwo.is_valid():
#.....do form2 valid stuff
return HttpResponseRedirect('/success')
if formone.is_valid() :
#....do form1 valid stuff
#formtwo = bookFormTwo()..if i add this the errors wont display but then errors from the first form spill over and it wont allow the second form to be valid...###
args = {'form2':formtwo,'isbn':isbn,'subject':subject}
args.update(csrf(request))
return render_to_response('book_post_form2.html', args,context_instance=RequestContext(request))
else:
args = {}
args['form'] = formone
args['form2'] = formtwo
args.update(csrf(request))
else:
form = bookFormOne()
args = {'form':form}
args.update(csrf(request))
return render_to_response('book_post.html', args,context_instance=RequestContext(request))
step_numberas a context variable, and validate forms based on that. That way, you can validate the correct step without any issues