Bonjour,
J'ai un tableau remplis, et j'aimerai update en base un champ lorsque je le modifie : c'est un select.
Je bidouille des choses et ce que j'ai commencé à faire est vraiment pas propre et pas adapté à symfony (j'ouvre une connexion pdo par exemple...), mais je ne comprends pas comment mettre à jour ma base autrement.
Mon objectif est de produire un code fonctionnel et doit rester propre. Je vais vous mettre là ce que j'ai codé pour le moment:
Mon tableau
Mon code javascript qui récupère l'id et la valeur qui a été modifiée) :
Code twig : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93 <table id="tableauAdmin" class="table-sm table-striped table-hover " width="100%" cellspacing="0"> <thead> <tr style="text-align:center"> <td>Formation</td> <td>Date de la justification</td> <td>Date du cours</td> <th></th> <th>Créneau</th> <td>Cours</td> <td>Etudiant</td> <th></th> <th>Justification</th> <th></th> <th>Etat justification</th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> {% for elementListePointage in listeDePointage %} <tr> <td>{{ elementListePointage.formation }}</td> <td>{{ elementListePointage.date }}</td> <td>{{ elementListePointage.dateCours }}</td> <td></td> <td><span class="badge badge-pills bg-info text-light">{{ elementListePointage.plageHoraireJustifAbscence }}</span></td> <td>{{ elementListePointage.cours }}</td> <td>{{ elementListePointage.prenomUtilisateur }} {{ elementListePointage.nomUtilisateur }}</td> <td>{{ elementListePointage.nomUtilisateur }}</td> <td ><a target="_blank" href="{{ asset('uploads/justifications/' ~ elementListePointage.lienFichier) }}"> <img style="margin: 0 35%" width="30" height="30" src="/uploads/logo_download.png"></a> </td> <td></td> <td> <div style="display: inline-block"> <input type="hidden" value="{{ elementListePointage.id }}" id="abs_id"> {% if elementListePointage.valider == "0" %} <select type="text" class="form-control col-lg-12 valider" id="Selector" style="color:orange"> <option style="color:orange;">En attente de validation</option> <option style="color:red;">Justification refusée</option> <option style="color:green;">Justification validée</option> </select> {% endif %} {% if elementListePointage.valider == "1" %} <select type="text" class="form-control col-lg-12 valider" id="Selector" style="color:red"> <option style="color:red;">Justification refusée</option> <option style="color:orange;">En attente de validation</option> <option style="color:green;">Justification validée</option> </select> {% endif %} {% if elementListePointage.valider == "2" %} <select type="text" class="form-control col-lg-12 valider" id="Selector" style="color:green"> <option style="color:green;">Justification validée</option> <option style="color:orange;">En attente de validation</option> <option style="color:red;">Justification refusée</option> </select> {% endif %} </div> <div class="success-checkmark" style="display: inline-block"> <div class="check-icon"> <span class="icon-line line-tip"></span> <span class="icon-line line-long"></span> <div class="icon-circle"></div> <div class="icon-fix"></div> </div> </div> </td> <td></td> <td></td> <td></td> </tr> {% endfor %} </tbody> <tfoot> <tr> <th>Formation</th> <th>Date de la justification</th> <th>Date du cours</th> <th></th> <th></th> <th>Cours</th> <th>Etudiant</th> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> </tr> </tfoot> </table>
La récupération de 'id' et 'valider' ne semble pas se faire et je n'ai aucun mouvement dans la console à ce niveau.
Code JavaScript : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <script> $(".check-icon").hide(); document.getElementById("Selector").onchange = changeListener; function changeListener(){ $("#Selector").slideDown().load("config/absenceUpdate.php", { id: $(this).closest('tr').find('#abs_id').val(), valider: $(this).closest('tr').find('.valider').val()}); } </script>
le absenceUpdate.php
Merci d'avance!
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 <?php try { $bdd = new PDO('mysql:host=localhost;dbname=mabase', 'mabase', '4cT82rffffW', array (PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));} catch (Exception $e) {die('Erreur : ' . $e->getMessage()) ; } $bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if(!empty($_POST['id'])) { $id = isset($_POST['id']) ? $_POST['id'] : NULL; $valider = isset($_POST['valider']) ? $_POST['valider'] : NULL; $update = $bdd->prepare('UPDATE abscences_justif SET id = :id, valider = :valider WHERE id = :id'); $update->execute(array( 'id' => $_POST['id'], 'valider' => $valider )); echo "<span class='success'>Votre facture a bien été modifiée.</span>"; } else { echo "<span class='error'>Votre facture a bien été modifiée.</span>"; }
Partager