how to use ajaxLink to perform a controller action

i want to use ajax link to perform a controllers action. i-e

i have a groups controller and i have an ajaxLink on it ( can’t figure out how to send the data through ajaxLink to groupMembers create action )

what i want is when the user clicks the ajax button a dialogbox should open and it may have confirmation button and captcha.

can anyone help me out with this situation???

try to use an ajaxSubmitButton

I think this is very close to what you want:

cjuidialog-and-ajaxsubmitbutton

thanx i had a look at it i think i will be able to understand it properly

so far after reading this(topic) i have came across this

in the groups view




echo CHtml::ajaxLink(Yii::t('Groups','Join Group'),

     $this->createUrl('groupmembers/create'),

     array(

     'type'=>'POST',

        'beforeSend'=>'function(){

             $("#joinGroup").addClass("loading");}',

        'complete' => 'function(){

            $("#joinGroup").removeClass("loading");}',

        'success'=>"function(data)

                  {

                    // handle return data

                   // alert( 'welcome' );

                    alert( data ); // it does alert the data

                    $('#joinGroup').replaceWith(data); // if i comment this no data is show even if i m using 'update'=>'#joinGroup'

                    

                  }",

        'data'=>array('groupID'=>$model->id,'userID'=>$currentUser,'ajax'=>'ajax'),

        'update'=>'#joinGroup' // joinGroup is a div in the view

        ),

     array('id'=>'joingroup'));



in the groupmembers controller




 public function actionCreate()

	{

	       $groupID = $_POST['groupID'];

           $userID = $_POST['userID'];

           

           $model=new Groupmembers;

           $model->group_id = $groupID;

           $model->user_id = $userID;

           

       	// Uncomment the following line if AJAX validation is needed

		 $this->performAjaxValidation($model);

         // Flag to know if we will render the form or try to add 

        // new member.

           $flag=true;

         if(isset($_POST['Groupmembers']))

    		{

    		  $flag=false;

              $model->attributes=$_POST['Groupmembers'];

              

              if($model->save()){

                    echo "welcome data is saved";


    			}else{

    			 echo "model not saved";

    			}

              

    		}

            if($flag){

                   $this->renderPartial('_formDialog',array(

    		      	'model'=>$model

    	           	),false, true);

            }


	}



and this the view (_formDialog) which is called in this view function





<?php $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

	'id'=>'mydialog',

	// additional javascript options for the dialog plugin

	'options'=>array(

		'title'=>'Join This Group',

		'autoOpen'=>true,

		'modal'=>true,

        

	),

));

?>

<h1>Join Group</h1>


<!-- echo 'dialog content here';-->


<div class="form">


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

	'id'=>'groupmembers-form',

	'enableAjaxValidation'=>false,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'group_id'); ?>

		<?php echo $form->textField($model,'group_id'); ?>

		<?php echo $form->error($model,'group_id'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'user_id'); ?>

		<?php echo $form->textField($model,'user_id'); ?>

		<?php echo $form->error($model,'user_id'); ?>

	</div>


      <?php if(CCaptcha::checkRequirements()): ?>

	<div class="row">

		<?php echo $form->labelEx($model,'verifyCode'); ?>

		<div>

		<?php $this->widget('CCaptcha'); ?>

		<?php echo $form->textField($model,'verifyCode'); ?>

		</div>

		<div class="hint">Please enter the letters as they are shown in the image above.

		<br/>Letters are not case-sensitive.</div>

		<?php echo $form->error($model,'verifyCode'); ?>

	</div>

	<?php endif; ?>


    <div class="row">

	

		<?php 

        

        echo CHtml::ajaxSubmitButton(Yii::t('Groups','Join Group'),

        CHtml::normalizeUrl(array('groupmembers/create','render'=>false)),

        array('success'=>'function(data) {

                       

                        alert(data);

                        

                    }'),

        array('id'=>'saveitem')); 

        

      

        

        echo CHtml::normalizeUrl(array('groupmembers/create'));

         ?>

	</div>




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


</div><!-- form -->




<?php 

$this->endWidget('zii.widgets.jui.CJuiDialog');


// the link that may open the dialog

echo CHtml::link('Join Group Now', '#', array(

	'onclick'=>'$("#mydialog").dialog("open"); return false;',

));

?>



now the main issues are:

[list=1]

[*]when i click on the join button it properly loads the dialog rendered from the controller but when i click on the submit button nothing happens

[*]as i have used the captcha too i no captcha or wrong captcha is entered or even no value is entered in any field the form is not validated and no errors are shown

[*]even if i input the right values in the form it is still not submitted, nothing happens

[/list]

can anyone plz tell me where i might be createing wrong logic or how to do it properly ?