S
S
serking772017-08-23 15:21:11
Yii
serking77, 2017-08-23 15:21:11

How to send post request to action in yii2?

Guys, tell me how can I send a Post request to an action from the form on the site?

public function actionForm()
    {
      $model = new ContactForm();

      if ($model->load(Yii::$app->request->post()))
       {
           $model->contact(Yii::$app->params['adminEmail']);
        }
        else {
            return 'произошла ошибка!!';
        }
    }

An error 400 is generated, what could be wrong with the request, or what kind of verification is needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tuerxor, 2017-08-23
@tuerxor

You are most likely making an ajax request. If so, then the controller has a property enableCsrfValidation, set it to false

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question