Form doesn't validate when passing form value to the next view
In my index view I have a ModelChoiceField which allows me to choose
various equipments.
When I have submitted my choice, I keep the selected value in a variable
like this:
if form.is_valid():
form.save()
request.session["eq"] = form.cleaned_data['equipment']
Then I am redirected to a new view(reservation) in which I have a form
with three fields: "equipment", "date" and "reserved_by". Since I have
already chosen the equipment i want in the previous view I want it to be
filled in automatically. I managed this by doing the following in my
reservation view:
form = ReservationForm(initial={'equipment': request.session.get('eq')})
So when I run my site, the equipment field in the reservation view does
get automatically filled in, but now the form suddenly won't
validate(form.is_valid is false).
Been struggling with this for a while now so any help would be highly
appreciative.
No comments:
Post a Comment