I am using Yii 2 basic application template. I have a controller called report and action called index. The index action will render the index.php file from the views directory. The index.php contains a form which accepts inputs from the user and when user clicks on the submit button then the processing takes place.
The processing should be self-processed (meaning it should process on the same page just as we used to do in normal PHP)
When I click on the submit button by providing the input, then Bad Request #400 is displayed as below
Controller: ReportController
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class ReportController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
index.php
<html>
<head>
<title>Total</title>
</head>
<body>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$n1=$_POST['number1'];
$n2=$_POST['number2'];
$c=$n1+$n2;
print "Addition = $c";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
Number 1 <input type="text" name="number1">
Number 2 <input type="text" name="number2">
<input type="submit" class="btn btn-primary" value="Submit">
</form>
</body>
</html>