L
L
Lev K2016-04-20 12:07:21
JavaScript
Lev K, 2016-04-20 12:07:21

How to insert php code into js event?

Hello!
I took the form _form.php formed by gii as a basis.
I created a button in it with an onclick event and an ajax request.
In success, you need to create a field, how can this be done?
I tried to create a div, but it did not work to push the php code into div.innerHTML.
How can I do that ? Or would you recommend another way to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-04-20
@Leffken

No need to shove php into js. There are only 3 options:
1. When sending an ajax request, return the html generated by php in response

return $this->renderAjax('_my_new_field',['somedata'=>$somedata]);
and process this html in success
2. Form html directly in success. using jquery, which is not very difficult (with the same structure with which activeform does it)
3. Create hidden fields on the server in advance, which fill with data and change visibility (and maybe position in the DOM) in success

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question