przewiń do treści

Symfony w przykładach

Włodzimierz Gajda

<a onclick="

    if (confirm('Jesteś pewien?')) {
      var f = document.createElement('form');
      f.style.display = 'none';
      this.parentNode.appendChild(f);
      f.method = 'post';
      f.action = this.href;
      var m = document.createElement('input');
      m.setAttribute('type', 'hidden');
      m.setAttribute('name', 'sf_method');
      m.setAttribute('value', 'delete');
      f.appendChild(m);
      var m = document.createElement('input');
      m.setAttribute('type', 'hidden');
      m.setAttribute('name', '_csrf_token');
      m.setAttribute('value', 'd5667ad15556b877d328c581423d9fbe');
      f.appendChild(m);
      f.submit();
    };
    return false;

" href="/piosenki-wojskowe/web/backend.php/piosenka/delete/piosenka_id/4">
        [usuń]
</a>

Listing 21.2. Hiperłącze generowane przez funkcję pomocniczą link_to() zawiera zabezpieczenie przed atakiem CSRF

Rozdział 21. Pierwszy panel administracyjny

listing-21-02.txt