Page not found when I am using POST method in my form

Hi.

In my view I had following code:


            <form action="index.php?r=site/buy" method="post" name="payment">

            <input name="price" value="24407" type="hidden">

            <input type="submit" class="btn btn-lg btn-primary" value="Buy" />

            </form>

And when I click on submit button I was redirected to correct page, but I get 404 error.

So it is with all the addresses which I’ll put in form action… Why?

I think that you are missing crsf token, needed to crsf validation:




$request = \Yii::$app->getRequest();

echo \yii\helpers\Html::hiddenInput($request->csrfParam, $request->getCsrfToken());



Where should I use this?




<form action="index.php?r=site/buy" method="post" name="payment">

<input name="price" value="24407" type="hidden">

<input type="submit" class="btn btn-lg btn-primary" value="Buy" />

<?php

$request = \Yii::$app->getRequest();

echo \yii\helpers\Html::hiddenInput($request->csrfParam, $request->getCsrfToken());

?>

</form>



or use ActiveForm