Link with DELETE method won't work in a form

Hi there.

I have a standard backend where I can delete models. I want to guard this action with the usual confirm message and to filter it with the DELETE verb in my controllers.

In my tags/index.php view, the delete link appears as a button like this :

<?= Html::a('<span class="glyphicon glyphicon-trash">', $url, [

    'class' => 'btn btn-danger btn-xs',

    'data' => ['confirm' => HLib::t('messages', 'Are you sure you want to delete this item?'), 'method' => 'delete',],

]) ?>

and the generated HTML is :

<a class="btn btn-danger btn-xs" data-method="delete" data-confirm="Etes-vous sûr de vouloir supprimer cet objet ?" href="">

<span class="glyphicon glyphicon-trash"></span>


The controller filters incoming requests as usual :

    public function behaviors()


        return [

            'verbs' => [

                'class' => VerbFilter::class,

                'actions' => [

                    'delete' => ['delete'],





This links appears in a custom grid view (not the yii\grid\GridView).

It works as expected : after the confirmation dialog, the request is processed and the object is deleted.

Now, in my form, I have the same code (same PHP code except for the button glyph, and same HTML generated code)

But when I click the ‘delete’ link in the form, Yii throws an error :

BTW, in access logs from Apache the accessed url is incorrect :

(valid URL :

I’m lost.

Any idea of what’s going on ?

HTML5 spec only allows GET and POST.

PUT and DELETE are not allowed so you can not do that

Why are there are no PUT and DELETE methods on HTML forms?

Interesting link and discussion, thanks for the tip.

Anyway, that’s not my point. I don’t want to send a DELETE request while SUBMITing my form. I want to send a DELETE request from a plain link (not a submit button, then) which happens to be be displayed into the form.

I can understand why HTML5 would not process a form action with a something else than PUT/GET. But once again, the link I am using does not cast any form action. It’s just a link, a plain link with a plain URL.

And :

1 - this URL is not called with the expected method. I guess the data-method attribute is processed somewhere in the javascript layer, but why this javascript would process it correctly in my grid view and not in my form ? And what could I do to avoid such distorsions ?

2 - this URL is corrupted somewhere since the incoming request in Apache does not show the URL actually displayed in the HTML code.

i may post the wrong link, but the point is for a URL link, you are restricted to GET or POST.

Linking to a page with a specific HTTP Method (DELETE)

to do a DELETE, you can hack your way by using jquery ajax and set method to DELETE

Hmm… data-method uses jQuery so DELETE request should be possible, I think.

is that something Yii2 does behind the scene for data-method DELETE ?