Wednesday, July 30, 2014

Re: simultaneously submit three forms on the same page

thank you very much .. how is the template for such a view ... I've put each form in a form tag like that


                    <form action=" " method="post">  {% csrf_token %}
                        {{ emet_form.as_p }}
                        <input type="reset" value="effacer" /> 


                    <form  action=" " method="post">  {% csrf_token %}
                        {{ des_form.as_p }}
                        <input type="reset" value="effacer" /> 

                    <form  action=" " method="post">  {% csrf_token %}
                        {{ fich_form.as_p }}
                        <input type="reset" value="effacer" /> 

                    <form  action="{%url 'formulaire.views.enregister'%}" method="post">  {% csrf_token %}
                     <input type="submit" value="enregistrer" /> 


On Tuesday, July 29, 2014 7:34:16 PM UTC, C. Kirby wrote:

They are not getting validated, or validation is failing?
Also, it looks like you are using model forms. You can get rid of all the for,.cleaned_data.get lines and just use:

if emet_form.is_valid() and des_form.is_valid() and fich_form.is_valid():
      emet =
      des =
      fich =

On Tuesday, July 29, 2014 10:53:59 AM UTC-5, Devin Cky wrote:

On Tuesday, July 29, 2014 1:48:00 PM UTC, Tom Evans wrote:
On Tue, Jul 29, 2014 at 12:31 PM, Devin Cky <> 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.


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():
      return HttpResponseRedirect(...)
    form_a = FormA()
    form_b = FormB()
    form_c = FormC()
  return render(...)



-------thank you TOM---
  when I submit my forms .. no field is validated


def enregistrer(request):
        if request.method == 'POST':
            emet_form = EmetteurForm(request.POST, prefix = "emet")
            des_form = DestinataireForm(request.POST, prefix = "des")
            fich_form = FichierForm(request.POST, prefix = "fich")
            if emet_form.is_valid() and des_form.is_valid() and fich_form.is_valid():
                    civilite = emet_form.cleaned_data.get('civilite')
                    nom = emet_form.cleaned_data.get('nom')
                    prenom = emet_form.cleaned_data.get('prenom')               
                    cni = emet_form.cleaned_data.get('cni')
                    mail = emet_form.cleaned_data.get('mail')
                    telephone = emet_form.cleaned_data.get('telephone')   
                    pays = emet_form.cleaned_data.get('pays')
                    ville = emet_form.cleaned_data.get('ville')
                    quartier = emet_form.cleaned_data.get('quartier')
                    emet =
                    nom = des_form.cleaned_data.get('nom')
                    prenom = des_form.cleaned_data.get('prenom')
                    mail = des_form.cleaned_data.get('mail') 
                    telephone = des_form.cleaned_data.get('telephone')
                    des =
                    description_fichier = fich_form.cleaned_data.get('description_fichier')
                    date_enregistrement = fich_form.cleaned_data.get('date_enregistrement')
                    observation = fich_form.cleaned_data.get('observation')
                    montant_prestation = fich_form.cleaned_data.get('montant_prestation')   
                    fich =
            emet_form = EmetteurForm()
            des_form = DestinataireForm()
            fich_form = FichierForm()
    return render(request,'formulaire/information.html',locals())            //***please look ..if my view is good***//

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment