form submitted twice???

I am rendering a view file. In that view file I am rendering a form via renderPartial(’_form’,array(some=>values),false,true);

The form is submitted via ajaxSubmitButton. When the button is clicked the form is submitted twice. Any idea why this behaviour?



Why won’t you use simple CHtml::submitButton ?

Because I have multiple forms in one page and would like my application to be cool 8) Also submitting some of the forms takes a while so i would like to use the loading class to indicate that the website is thinking…that kind of stuff

any thoughts?



I don’t know, Never had this sort of behavior. Maybe there something in your code that does that. I can try and reproduce the same issue if you share your code with us.

_view.php file:

<?php echo CHtml::beginForm('','post',array('name'=>'csgen')); ?>

                <div class="genlistbox">

                            <?php if(!empty($correctData)): ?>

                            <?php  echo CHtml::listBox('Events','',$correctData,array(



                                                        	'all'.$lname=>'Select all',




                            <?php endif; ?>


                <div class="gen_body">

                            <?php if(!empty($correctData)): ?>

                            <?php echo CHtml::ajaxSubmitButton("",



                                        'type'=>'post',//submit via POST


                                        'beforeSend' => 'function(){


                                        'complete' => 'function(){









                            <?php endif; ?>


        <?php echo CHtml::endForm(); ?>

When the above code is placed directly in the view file all works fine. When however placed in the view file via renderPartial it always submits the form twice. If I have two such forms through renderPartial it submits 4 times no matter that only one form is submitted. I’ve made sure all ajaxSubmitButtons have unique names and the forms have unique names.

Here is the renderPartial:


Please let me know if you see anything wrong in my code



Either there must be something wrong with the renderPartial or there must be something wrong with the way I am using it.

One interesting test would be to assign a unique name (counter) to the ajaxButton on each renderPartial.


Interesting. I assigned a unique parameter to each renderPartial. All came down to the conclusion that each renderPartial submit itself twice. Not sure why. Did another test by declaring the renderPartial like this:


and now it works as expected[only submitting itself once].

Any idea why the last two parameters are forcing a second submission of the form?



I don’t know why you started to use the fourth parameter of renderPartial set to true (IIRC in another thread you were advised to use it).

With the call used in recent versions of CHtml I guess a lot of event rearming kind of problems went away. But I can’t imagine every possible case.

With the fourth parameter set to true, one problem is that jQuery may be included more than once

See this thread.

A worse problem (that’s probably what hit you) is that multiple jQuery stubs would be generated in the document.ready script section.

I don’t know the exact reason why some people (some configurations) run into problems. Like others suggested, perhaps a hardware and browser dependent DOM update race condition. Possibly it might be a good idea to modify CHtml to set of a delay before modifying jQuery stubs. I’m just guessing here, didn’t investigate.


This thread is old but I’ll reply because it comes up in google search results.

Two submits is usually because of Ajax validation, which does the extra submit before the real one. If that’s not processed right, it will behave as two functional submits.

If you have AjaxValidation enabled on the form view page, you must:

  1. Enable it in your controller for that form (default CRUD generation has it commented out)

  2. Make sure the form name (e.g. “user-form”) on the form is the same name as used in the controller’s performAjaxValidation test.

While your answer are useful with respect to the thread title, the above scenario doesn’t involve CActiveForm, so ajax validation isn’t used in this case.


Hi, I know this is a very old thread, but I’m having a similar issue where it’s doing two submits. The problem, though, is that if I change the fourth parameter of renderPartial() to false, then my time-pickers and sliders (which are dynamically loaded) don’t display on the form.

Any suggestions?