Yii2. I have two forms:
First - site.com/test1/form1
when I choose Test1
, Ajax loads the data from the database in Test2
and Test3
But I need to load the data into a second form. I select Test1
in Form1
, then I'm creating this form. After that I go to create Form2
, and when form opens I see the downloaded data.
StreetsController.php for data:
public function actionGetNM($id)
{
$street = Streets::findOne($id);
echo Json::encode($street);
}
In _form1:
$script = <<< JS
$('#form1-test1').change(function(){
var id = $(this).val();
$.get('/streets/get-n-m',{ id : id },function(data){
var data = $.parseJSON(data);
$('#form1-test2').attr('value',data.n);
$('#form2-test3').attr('value',data.m);
});
});
JS;
$this->registerJs($script);
I think that after creation Form1
need to get id
form1
and transmit on form2
, where Ajax gets data from Json. It's all in theory, I don't understand how to implement it. Can anyone help?