form and ajax problem

I use this form (and below the action).

My problem is that the ajax request seems not to working what is wrong?

echo "<form name='".$item['id']."' id='".$item['id']."' action='".CHtml::normalizeUrl(array('card/RemoveElement'))."' 

 method='post'><input type='hidden' id='idd'  

name='idd' value='".$item['id']."'/>";

 echo CHtml::ajaxSubmitButton('remove', CHtml::normalizeUrl(array('card/RemoveElement')), array('replace'=>'doing'));

 echo "</form>";

public function actionRemoveElement()

    { if (!empty($_POST['idd']))







Seems quite strange, since action methods normally don’t have arguments, yet you want to pass an int to actionRemove.

Refactor your code so that actionRemoveElement calls a model to delete itself.

I make a model cart for the cart.

But at my page I see that the request is not doing.

The code that yii writes is




jQuery("doing").replaceWith(html)}});return false;});

As I see parents find all elements of dom and at this occassion the elements those are ‘form’ (as I understand).

At this page there are many forms, so I can not use this function of Yii?

I change the javascript code as


'cache':false,'data':jQuery("#form").serialize(),'success':function(html){alert(html);}});return false;});

And it worked for me.

Is there any chance you accidentally implemented nested form tags?

As of jQuery documentation, parents() should not conflict with separate forms.

Furthermore, I see you changed #yt2 to #yt1, which also doesn’t make sense if you used forms correctly.

I manage to run the script but now the update is here for just the first time.What is wrong?

Edit:Also the remove function run only if the page is not been "updated",how can I solve this?



echo "<h2></h2>";

echo "<div id='card'>";

if($cart->get_itemcount() > 0) {

    foreach($cart->get_contents() as $item) {

        echo "<br />Item:<br/>";

        echo "Code/ID :".$item['id']."<br/>";

        echo "Quantity:".$item['qty']."<br/>";

        echo "Price   :$".number_format($item['price'],2)."<br/>";

        echo "Info    :".$item['info']."<br />";

        echo "Subtotal :$".number_format($item['subtotal'],2)."<br />";

        echo CHtml::beginForm(CHtml::normalizeUrl('Card/RemoveElement'),'post');

        // echo "<form name='".$item['id']."' id='".$item['id']."' action='".CHtml::normalizeUrl(array('card/RemoveElement'))."'  method='post'>

        echo  "<input type='hidden' id='id'  name='id' value='".$item['id']."'/>";

        echo CHtml::ajaxSubmitButton('remove', CHtml::normalizeUrl(array('card/RemoveElement')), array('update'=>'#doing'));

        echo "</form>";


    echo "---------------------<br>";

    echo "total: $".number_format($cart->get_total(),2);

} else {

    echo "No";


echo "</div >";?>