CActiveForm and ajaxSubmitButton

Hi,

the action “main/sets” render’s a view with an CActiveForm inside:


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

	'id'=>'search-sets-form',

	'enableAjaxValidation'=>true,

));?>

The form-data should be send to a specific controller/action called "ajax/postings". For this, a ajaxSubmitButton is part of the CActiveForm:


<?php echo CHtml::ajaxSubmitButton('Submit', $this->createUrl('ajax/postings'),

					array('success'=>'function(data){ $("#searchSetDialog").dialog("close");

                                                                            return false;}')

 				);?>

If the user submit the data without any changes (simple press the submit button) everything work fine.

If the user do any changes at the form and submits the form, 2 POST request are created:

1st POST to the contoler/action defined at the ajaxSubmitButton ("ajax/postings") and

2nd request to the controller/action where the form comes from ("main/sets").

Is there any way to avoid the form sending POST data to "main/sets"??

Thank you, rall0r

Byt the way: Ajax-Validation works fine. Validation Requests where send to the AjaxSubmitButton-Url: action "ajax/postings". ?:-/

Problem is solved!

Explanation:

The reason for the 2nd POST Request to the controler where the form was rendered ("the current page URL") is ajax validation (which is true/active).

CActiveForm tries to validate the data at the time of sendig the data.

At this application, the ajax validation should happend in the action: ‘ajax/postings’

So I have to set the default action for the form:


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

        'id'=>'search-sets-form',

        'enableAjaxValidation'=>true,

        'action'=> CHtml::normalizeUrl(array('ajax/postings')),

));?>

:slight_smile: