Ajax form submition problem.

I have problem with using ajax in forms.




 <?php

    $this->form = $this->beginWidget('CActiveForm', array(

                'id' => 'node-form',

                'enableAjaxValidation' => true,

                'enableClientValidation' => true,

                'clientOptions' => array('validateOnSubmit' => true),

                'htmlOptions' => array('enctype' => 'multipart/form-data'),

            ));

    echo $this->form->hiddenField($this->node->nodeType, 'id');

    ?>


    <div class="row">

        <?php echo $this->form->labelEx($this->node, 'name'); ?>

        <?php echo $this->form->textField($this->node, 'name', array('size' => 60, 'maxlength' => 255)); ?>

        <?php echo $this->form->error($this->node, 'name'); ?>

    </div>




    <div class="row">

        <?php $this->generateField('Obrazek'); ?>

    </div>

    <div class="row">

        <?php $this->generateField('Opis'); ?>

    </div>

    <div class="row buttons">

        <?php echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Create' : 'Save', 'admin/content/update/' . $this->node->id); ?>

    </div>


    <?php $this->endWidget(); ?>



When i submit form ajax is not used. Javascript is enabled because this form is loaded to jquery dashboard widget. Is it possible that this is the reason of this problem?

Ok I know that it is because form is loaded to dashboard. Is there way to load javascript for ajaxButton/ajaxSubmitButton with form?

i once found myself in this kind of problem so i decided to use the chtml::ajaxbutton

then defined by ajax options.

an example




echo chtml::ajaxbutton('call ajax',$this->createUrl('g/ajaxLookup'),array('success'=>'function(data){ alert(data);}','beforeSend'=>'function(){$("id-accept").addClass("loading");}));




and it worked fine


<?php echo CHtml::ajaxSubmitButton($model->isNewRecord ? 'Create' : 'Save', 'admin/content/update/' . $this->node->id); ?>

‘admin/content/update/’ . $this->node->id

change to

Yii::app()->createUrl(‘admin/content/update/’).$this->node->id

may be right??

@binkabir

Unfortunately it do not help, i think it is caused by not including jquery.yiiactiverecord.js, and do not attaching onclick event to button when it is added to dashboard.

@qijunz

URL is not an issue, i have used CController::createUrl(), and it didn’t change anything. Issue is that it do not send anything when I use ajaxButton or works as regular submit button when i use ajaxSubmitButton.

I will heave to add content to widgets in some different way.

I will tell what I am trying to do, maybe it will help in finding solution.

I want to have submit form in jquery.dashboard (plugin | examples). It adds widgets based of JSON feed, each widget has several parameters like column id. Content is added based on url. So if I add to parameter "url" value "http://yiiframework.com" content of site would be paste to widget. I have created DashboardController and action which generates widget content (form for adding content).