[英]Form not POST ing
this is my view where there is a form containig a field and a submit button. 这是我的观点,那里有一个包含字段和提交按钮的表格。
<form id="typeheadForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-3 control-label">Movie</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="state" id="movie_name" />
</div>
</div>
<input type='submit' name='submit' value='Search' class="btn btn-squared btn-default">
</form>
and below is my controller code 以下是我的控制器代码
public function actionMovies_all()
{
$this->layout = "main";
if ( isset( $_POST[ 'movie_name' ] ) )
{
print_r("success");die();
}
if ( Yii::$app->request->post() )
{
print_r(Yii::$app->request->post());die();
}
}
i am not able to POST the form. 我无法过帐表格。 what am i doing wrong?
我究竟做错了什么? i am getting an error " Bad Request (#400) Unable to verify your data submission."
我收到错误消息“错误的请求(#400)无法验证您的数据提交。”
Replace <form id="typeheadForm" method="post" class="form-horizontal">
with 将
<form id="typeheadForm" method="post" class="form-horizontal">
替换为
<?= \yii\helpers\Html::beginForm('', 'post', ['id' => 'typeheadForm', 'class' => 'form-horizontal']);?>
You are getting bad request
because when you create your form manually, you did not include csrf token into it. 您收到的
bad request
因为当您手动创建表单时,没有在其中包含csrf令牌。 When you create form with Html::beginForm
method it takes care about it internaly. 当您使用
Html::beginForm
方法创建表单时,它会在内部对其进行处理。
try this: 尝试这个:
public function actionMovies_all()
{
$this->layout = 'main';
if ( isset( $_POST[ 'submit' ] ) )
{
print_r('success');die();
}
if ( Yii::$app->request->post() )
{
print_r(Yii::$app->request->post());die();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.