Stay In Same Page (Load Jquery Onclick Button)

Hi all,

I have a button that have an event (onClick) that calls a javascript. In this js have a load() function that load a div from another model (don’t this where is my button).

When the div of another model is loaded, I have a form that I fill and I click in a submit button (now is from the form of my div).

When I click in this submit button, I wanna that the model->save() be executed and stays on the same page, but the render() function of my controller redirects me to the create.php page.

How do this? How to keep in same page?

I wanna this:

5547

Screenshot 2014-05-09 20.32.01.png

When I click in the label "Adicionar nova filiação", my other _form is called and shown, like in the Image.

But, when I press in OK button of this form (Filiacao), I need that the data be stored on the database (this is ok [actionCreate()]) and stay on this page.

Someone help me, pls?

Anyone?

Can you post your codes relating to the problem?

You should use ajaxSubmitButton.

Hi,

thanks for your answer.

I have this button:




        <?php

            $this->widget(

                  'bootstrap.widgets.TbButton',

                  array(

                        'type' => 'primary',

                        'buttonType' => 'ajaxButton',

                        //'buttonType' => 'link',

                        'label' => 'Adicionar nova Filiação',

                        'htmlOptions'=> array(

                            'id'=> 'bt'

                            'onClick' => "$('#divFiliacao').load('/museu_emigracao/index.php/filiacao/create #divFiliacaoExt');"

                        )

                  ));

        ?>



That load the <div> of my Filiacao _form and when I click on the submit button of the Filiacao _form that load() function call, the page is redirected and I don’t wanna this.

My submit button of Filiacao _form:




            $this->widget(

                  'bootstrap.widgets.TbButton',

                  array(

                        'type' => 'primary',

                        'buttonType' => 'submit',

                        'label' => 'OK',

                        )

                  );



In other words, what I need is save data from a model (Filiacao) that was loaded into a model (identificacaoEmigrante). IE, how to use $model->save() without render() / redirect to another page in controller?

Add a condition like this to the ‘render’ in your controller:




    if(!Yii::app()->request->isAjaxRequest) {

        $this->render('view', array('model' => $model,);

    }



Use ajaxSubmit, I haven’t tested it since I am not using that bootstrap,

But since you’re submitting a form through ajax, you should use ajaxSubmit,


$this->widget(

 	'bootstrap.widgets.TbButton',

 	array(

     	'type' => 'primary',

     	'buttonType' => 'submit', // use ajaxSubmit

     	'label' => 'OK',

 	)

);

That’s it.

I corrected the problem with an ajaxButton.

Thanks.

Please vote it up :) haha