Bonjour,

J'aurais besoin de votre aide. Je précise auparavant que j'ai fait le tour des forums mais aucune solution ne fonctionne..
J'ai une entité TableMark composé d'une clé composite et de deux champs. Je dois via un formulaire ajouter un utilisateur à un objet TableMark. J'aimerai donc afficher ce formulaire dans un modal (popup) qui affichera la liste d'utilisateur. Cependant j'ai une erreur : CRSF token is invalid.

Entité TableMark :
Code : 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
 
class TableMark {
 
    /**
     * @ORM\ManyToOne(targetEntity="Basket\LibrairyBundle\Entity\User", inversedBy="tableUsers")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     * */
    private $user;
 
    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Basket\LibrairyBundle\Entity\Game", inversedBy="tableGames")
     * @ORM\JoinColumn(name="game_id", referencedColumnName="id")
     * */
    private $game;
 
    /**
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Basket\LibrairyBundle\Entity\RoleOTM", inversedBy="tableRoleOTMs")
     * @ORM\JoinColumn(name="roleOTM_id", referencedColumnName="id")
     * */
    private $roleOTM;
 
    /**
     * @ORM\ManyToOne(targetEntity="Basket\LibrairyBundle\Entity\Outsider", inversedBy="tableOutsiders")
     * @ORM\JoinColumn(name="person_id", referencedColumnName="id")
     * */
    private $outsider;
}
Vue de la liste des games :
Code : 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 
{% block basketadmin_body %}
        <link rel="stylesheet" href="{{ asset('bundles/basketlibrairy/plugins/select2/select2.min.css') }}">
        <script type="text/javascript" charset="utf8" src="{{ asset('bundles/basketlibrairy/plugins/jQuery/jQuery-2.1.4.min.js') }}"></script>
    <script src="{{ asset('bundles/basketlibrairy/plugins/select2/select2.full.min.js') }}"></script>
 
    <div id="test">
                <table class="table table-bordered table-color">
                        <tr>
                        <th>Jour</th>
                        <th>Heure</th>
                        <th>Poste</th>
                        <th>Personne</th>
                        <th>Action</th>
                        </tr>
                        {% for game in listgamedays %}
                                {% for tableGame in game.tableGames %}
                                        {% if tableGame.roleOTM.name == 'chronometreur' %}
                                        <tr>
                                                <td rowspan="2">{{ game.dateGame|date('d-m-Y') }}</td>
                                                <td rowspan="2">{{ game.hourBegin|date('H:i:s') }}</td>
                                                <td>{{ tableGame.roleOTM.name }}</td>
                                                {% if tableGame.user %}
                                                <td> {{ tableGame.user.username }} </td>
                                        {% elseif tableGame.outsider %}
                                                <td> {{ tableGame.outsider.name }} </td>
                                        {% else %}
                                                <td>Personne</td>
                                        {% endif %}
                                        {% if tableGame.user or tableGame.outsider %}
                                                <td>
                                                        <a href="{{path('basket_admin_choose_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-info btn--sqxs btn-load-modal" title="Modifier">
                                                    <i class="fa fa-pencil"></i>
                                                </a>
                                    <a href="{{path('basket_table_remove_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-sq-xs btn-danger" data-toggle="tooltip" title="Supprimer">
                                        <i class="fa fa-times"></i>
                                    </a>
                                                </td>
                                        {% else %}
                                                <td>
                                    <a href="{{path('basket_admin_choose_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-info btn-sq-xs btn-load-modal" title="Ajouter">
                                                    <i class="fa fa-plus"></i>
                                                </a>
                                                </td>
                                        {% endif %}
                                        </tr>
                                        {% else %}
                                        <tr>
                                                <td>{{ tableGame.roleOTM.name }}</td>
                                                {% if tableGame.user %}
                                                <td> {{ tableGame.user.username }} </td>
                                        {% elseif tableGame.outsider %}
                                                <td> {{ tableGame.outsider.name }} </td>
                                        {% else %}
                                                <td>Personne</td>
                                        {% endif %}
                                                {% if tableGame.user or tableGame.outsider %}
                                                <td>
                                                        <a href="{{path('basket_admin_choose_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-info btn-sq-xs btn-load-modal" title="Modifier">
                                                    <i class="fa fa-pencil"></i>
                                                </a>
                                    <a href="{{path('basket_table_remove_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-sq-xs btn-danger" data-toggle="tooltip" title="Supprimer">
                                        <i class="fa fa-times"></i>
                                    </a>
                                                </td>
                                        {% else %}
                                                <td>
                                    <a href="{{path('basket_admin_choose_user_table', { 'id_game': game.id, 'poste_name': tableGame.roleOTM.name, 'id_day': day.id }) }}" class="btn btn-info btn-sq-xs btn-load-modal" title="Ajouter">
                                                    <i class="fa fa-plus"></i>
                                                </a>
                                                </td>
                                        {% endif %}
                                        </tr>
                                        {% endif %}
                                {% endfor %}
                        {% endfor %}
                </table>
        </div>
        <style>
                .table-color {
                        border: 1px solid #000000;
                }
        </style>
 
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body">
 
                </div>
            </div>
        </div>
    </div><br><br>
    <script>
        $("#test").on('click', '.btn-load-modal', function (e) {
            $.ajax({
                type: "POST",
                url: $(this).attr("href"),
                success: function (data) {
                    $('.modal-body').html(data);
                },
                complete: function () {
                },
                beforeSend: function () {
                    $('#myModal').modal('toggle');
                    $('.modal-body').html("<div class='progress' id='loadingDiv'><div class='progress-bar progress-bar-striped progress-bar-success active' role='progressbar' \n\
                                        aria-valuenow='100' aria-valuemin='0' aria-valuemax='100' style='width: 100%'></div></div>");
                },
                error: function (xhr, ajaxOptions, thrownError) {
                                alert(xhr.status);
                                alert(thrownError);
                            }
            });
            return false;
        });
    </script>
{% endblock %}
Vue avec le formulaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
<form method="post" action="{{ path('basket_admin_choose_user_table', { 'id_game': id_game, 'poste_name': poste, 'id_day': id_day }) }}" {{ form_enctype(form) }}>
 
    {{ form_widget(form) }}
 
    <input type="submit" class="btn btn-primary"/>
 
</form>
Controller :
Code : 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
 
    public function chooseUserTableAction(Request $request, $id_game, $poste_name, $id_day) {
        $em = $this->getDoctrine()->getManager();
 
        $tableMark = new TableMark();
        $form = $this->createForm(new TableMarkType(), $tableMark);
 
        $request = $this->getRequest();
        if ($request->getMethod() == 'POST') {
            $form->bind($request);
            if ($form->isValid()) {
                return $this->redirect($this->generateUrl('basket_admin_table_list_gameday', array('id' => $id_day)));
            }
        }
 
        return $this->render('BasketAdminBundle:Table:addUserTable.html.twig', array(
                    'id_game' => $id_game,
                    'poste' => $poste_name,
                    'id_day' => $id_day,
                    'form' => $form->createView()
        ));
    }
 
    public function addUserTableAction(Request $request, $id_game, $poste_name, $id_day) { -> action non terminée
        $em = $this->getDoctrine()->getManager();
 
        $poste = $em
            ->getRepository('BasketLibrairyBundle:RoleOTM')
            ->findOneBy(array('name' => $poste_name));
        $table = $em
                ->getRepository('BasketLibrairyBundle:TableMark')
                ->findOneBy(array('game' => $id_game, 'roleOTM' => $poste->getId()));
 
        if ($table->getUser() === null && $table->getOutsider() === null) {
            $user = $request->request->get('usertable');
 
            $tableMark = $em
                ->getRepository('BasketLibrairyBundle:TableMark')
                ->setUserTable($user->getId(), $id_game, $poste->getId());
            ;
            $tableMark->execute();
        }/* elseif ($table->getUsername != ) {
 
        }*/
 
        return $this->redirect($this->generateUrl('basket_admin_table_list_gameday', array('id' => $id_day)));
    }
Merci d'avance pour votre aide..