M
M
MaikMain2018-04-15 21:34:14
Yii
MaikMain, 2018-04-15 21:34:14

How to display a form in one controller, action and view, and send data to another?

Good evening, please tell me how to make a form in one controller and action, and send the data to another?
I have a "Book" model, a "BookController" controller and an "actionView" method that renders a "view" view and I need to make a form in it via an ActivForm.
Output 1 field ("animal_id") that belongs to the "Lead" model. And you need to pass the value that falls into "animal_id" to "actionCreate".
I do like this:

<?php $form = ActiveForm::begin([
    'method' => 'get',
    'action' => ['lead/create'],
]); ?>
<?= $form->field($model, 'animal_id',['options' => ['class' => 'col-xs-6']]);
?>
<?= Html::submitButton('Ок', ['class' => 'btn btn-success']) ?>
<?php ActiveForm::end(); ?>

But an error is thrown: Call to a member function isAttributeRequired() on null
Tell me how to be and what to do? Thank you very much in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
ZaurK, 2018-04-15
@ZaurK

If I understand correctly, you want to link two different models in one form, look here

D
Dmitry Kim, 2018-08-14
@kimono

But an error is thrown: Call to a member function isAttributeRequired() on null

And in $modelyou it is casual not nullat a stage of an output of the form?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question