1

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."

Bloodhound
  • 2,906
  • 11
  • 37
  • 71
  • you didn't close your input (submit ) tag but I doubt that is the issue. your also mixing ' single and " double quotes, which is just ugly. And you don't have an action="?" in your form which might be an issue. – ArtisticPhoenix Jul 08 '15 at 04:16
  • i tried like this but it didnt work – Bloodhound Jul 08 '15 at 04:34
  • Sorry I don't know Yii so I have no idea if that would work. But you should look at the source of the page and make sure it goes where it should. ( right click > view source ) then ctrl+f to find the word "form" and check that that is your url or what have you. – ArtisticPhoenix Jul 08 '15 at 04:46

2 Answers2

2

Replace <form id="typeheadForm" method="post" class="form-horizontal"> with

<?= \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. When you create form with Html::beginForm method it takes care about it internaly.

Tony
  • 5,797
  • 3
  • 26
  • 22
0

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();
        }
    }
Insane Skull
  • 9,220
  • 9
  • 44
  • 63