Ajax Validation In Fancybox - Wrong Action

Hi all.

I have a problem with Ajax validation in Fancybox.

I have an ajaxLink that opens Fancybox with a form. This form should be send via Ajax to controller and validated, but wrong action is used automatically and I can’t change it.

AjaxLink that opens and fills Fancybox is defined in View like this:


$ajaxOptions = array(

    'success' => "function(data) { $.fancybox({content:data}); } ",

);

echo  CHtml::ajaxLink('open', $this->createUrl('links/test1'),$ajaxOptions);

Action "test1" prints this form which is shown in Fancybox:




echo CHtml::form($this->createUrl('links/save'));

echo CHtml::textField("mytext", "text");

$ajaxOptions = array(

    'url'=>$this->createUrl('links/save'),

);

echo CHtml::ajaxSubmitButton('save',$this->createUrl('links/save'),$ajaxOptions);

echo CHtml::endForm();



But if I click the "save" button, action "test1" is called. Not action "save".

Does anybody know what is wrong?

post the controller code?

I think controller is not important here. Problem is in the ajaxSubmitButton() and using JS by Yii. My controller is empty. It contains only code that is mentioned above. But…


class LinksController extends Controller

{

    public function actionTest1() 

    {

        $output = $this->renderPartial('form', array(), true);

        echo $output;

        Yii::app()->end();

        return;

    }


    public function actionSave() 

    {

    }

}

PS: I think that if I use rednerPartial() (or if I print something in an action - which is the same), Yii doesn’t add some JS code so ajax doesn’t work. Because if I program it by myself (using global JS file, classes and events), everything goes well.

If you want to renderPartial add JS code, pls edit your code:




class LinksController extends Controller

{

    public function actionTest1() 

    {

        $output = $this->renderPartial('form', array(), true, true);

        echo $output;

        Yii::app()->end();

        return;

    }


    public function actionSave() 

    {

    }

}