Tuesday, July 29, 2014

Re: simultaneously submit three forms on the same page

On Tue, Jul 29, 2014 at 12:31 PM, Devin Cky <vin100jo@gmail.com> wrote:
> hi i am a beginner in django and I have a problem .. how can I validate 3
> forms on the same page simultaneously ..please help me
>

If they are different types of forms, you cannot use a formset.

In that case, just test whether all forms are valid. If they are all
valid, save/process the forms. If not, re-render the page with the
bound forms and display the errors.

Eg

def myview(request):
if request.method == 'POST':
form_a = FormA(request.POST)
form_b = FormB(request.POST)
form_c = FormC(request.POST)
if form_a.is_valid() and form_b.is_valid() and form_c.is_valid():
form_a.save()
....
return HttpResponseRedirect(...)
else:
form_a = FormA()
form_b = FormB()
form_c = FormC()
return render(...)

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1LJjfHOk43FzQjjVzppo4N5QbqHiwGFjO8SFwowWTzGug%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment