Answer the question
In order to leave comments, you need to log in
How to submit two forms on one Yii2 action?
Hello.
---
My background: about six years ago, when I didn't know about Yii yet, there were such tasks, to send two or three forms from one page, and it was done simply, by name.
Roughly speaking, if the
Then button in the conditions you write:<input type="submit" name="send"/>
<?php
if(isset($_POST['send'])){
// то происходит это
}
?>
<input type="submit" name="rezult"/>
<?php
if(isset($_POST['rezult'])){
// то происходит это
}
?>
...
if(isset(Yii::$app->request->post('send')){}
...
<?= Html::submitButton('отправить', ['name' => 'send', 'class' => 'btn btn-primary']) ?>
Html::beginForm();
. Answer the question
In order to leave comments, you need to log in
The solution is very simple:
...
$string = Yii::$app->request->post('send');
if (isset($string)) {
...
}
...
Good afternoon.
Look in the documentation, there is such a method as formName(), if I'm not mistaken.
Check what this method returns, write code based on it.
but the form is one, but the action is not one? What prevents this form class from implementing two methods that are launched from button[name=btn][value=send] or button[name=btn][value=result]?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question