Hi I have a user form and I want to add a button so that the user can add more contacts dynamically.
You can do it like below:
Write the following code into your view:
$this->registerJs('$("#btnadd").on("click",function(){'
. '$("#dynamicInput").append(\''
. Html::tag("div", Html::textInput("name","",['placeholder'=>"name"]))
. Html::tag("div", Html::textInput("email","",['placeholder'=>"email"]))
. '\');'
. '})');
Please note that you need to have:
use yii\helpers\Html;
at top of your page. Otherwise, you should write yii\helpers\Html::
instead of Html::