modal window not loading form

Hello all,

I have a view accessed (using pretty urls) via:


Ok, so I have another view with a java event that is supposed to open the above view as modal:

$JSCode = <<<EOF







$JSCode = str_replace('{URL}', Url::toRoute(['/event-parent/createl']), $JSCode);

So the above Jquery is being called, but when the modal window pops up it’s empty.

Here is the modal code



    'header'=>'<h4>Create Event</h4>',




    echo "<div id='modalContent'></div>";



Never mind! Had a typo!

had a rogue l on the end of the word create, the below now works.

$JSCode = str_replace('{URL}', Url::toRoute(['/event-parent/create']), $JSCode);

I still have an issue.

Ok so I went by this video

And the idea is that I press submit on my modal window, and it supposed to submit the form, close the modal, and refresh the background via Ajax.

It’s falling over for me as I am pressing the submit button, then the browser will go directly to event-parent/create and display 1 (meaning the form submitted successfully)


So I guess the question here, how do I make the submit a background task that does not redirect the current view?[/b]

If it helps here is the code I am using in Jquery on my event-parent/create _form.php:


$script = <<< JS

$('form#{$model->formName()}').on('beforeSubmit', function(e)


    var \$form = $(this);


        \$form.attr("action"), //serialize Yii2 form



        .done(function(result) {

        if(result == 1)











            console.log("server error");


    return false;





i answered a similar question the other day.


you are probably telling the controller to redirect to a page. You can either remove the redirect line if this action will only be done via ajax/pjax or catch the pjax/ajax request and tell it to skip the redirect.