-1

please i tried with this How can I build multiple submit buttons django form?

but it doesnt work for me and im new to django programming my aim is : when the user enter the identifiant when he clicks on the button recherche i want that all information come on the input tags here is my code views.py:

def modifierEmploye(request):
    if request.method=='POST':
    emp2=EmployeForm(request.POST)
    if emp2.is_valid():
        if 'recherche' in request.POST:
            return HttpResponse("recherche")
        elif 'enregistrer' in request.POST:
            return HttpResponse("enregistrer")
else:
    emp2=EmployeForm()

return render(request,"GPI/modifierEmploye.html",locals())

html:

<form action="" method="POST">
        {% csrf_token %}
        <p> <input id="id" maxlength="200" name="id" type="text" placeholder="identifiant"  /></p><br>
        <p> <input id="id_nom" maxlength="200" name="nom" type="text" placeholder="Nom"  /></p><br>
<p><input id="id_prenom" maxlength="200" name="prenom" type="text" placeholder="Prenom"/></p><br>
<p> <input id="id_departement" maxlength="200" name="departement" type="text" placeholder="Département"  /></p><br>
<p> <input id="id_poste" maxlength="200" name="poste" type="text" placeholder="Poste" /></p><br>
<p> <input id="id_telephone" maxlength="200" name="telephone" type="text" placeholder="Téléphone"  /></p><br>
<p><input id="id_email" maxlength="200" name="email" type="email" placeholder="Email"  /></p>
<p> <input id="id" maxlength="200" name="id" type="text" placeholder="Nom"  /></p><br>
<br>
        <input type="submit" value="Rechercher" name="recherche" />
        <input type="submit" value="Enregistrer" name="enregistrer"  />





    </form>

this program doesn't work, please qomeone to help me

Community
  • 1
  • 1
  • You haven't said what the problem is. What does not work? You haven't even stated what you want the different behaviour to be. – Daniel Roseman Nov 20 '14 at 12:54
  • i want that when i click on the button rechercher i will send a web page contains "recherche" and when i click enregistrer "enregistrer" i edited my problem. beg pardon –  Nov 20 '14 at 13:57
  • 1
    And what *do* you see instead? Are you sure the form is valid? Have you tried outputting `form.errors` in the template? – Daniel Roseman Nov 20 '14 at 13:58
  • when i click i receive again the same form whithout data, the form at the begining of test is valid. please how can i use form .errors ? beg pardon –  Nov 20 '14 at 14:13
  • Obviously you receive the same form without data, because you have hard-coded your inputs in HTML rather than using Django to render them complete with data. And to use form.errors you just put `{{ form.errors }}`. Seriously, this is all really basic stuff that is well covered in the docs: you should at least read through the tutorial and then the guides on how to use forms. – Daniel Roseman Nov 20 '14 at 14:16
  • Thanks Daniel for the help, i have question, You said that i have hard-coded mu inputs in HTML, can you please tell me exact what is the good manner to code my template? beg pardon –  Nov 20 '14 at 14:20
  • Like I just said, you should read the docs. There is a whole section on [Working with form templates](https://docs.djangoproject.com/en/1.7/topics/forms/#working-with-form-templates). – Daniel Roseman Nov 20 '14 at 14:24

1 Answers1

0

change your template with this, it will work :

<form action="" method="POST">
        {% csrf_token %}
        {{emp2.as_p}}
        <input type="submit" value="Rechercher" name="recherche" />
        <input type="submit" value="Enregistrer" name="enregistrer"  />

    </form>