Two submit buttons , one form

Hi Guys,

I have two CHtml::submitButton() in my form, namely "Accept" and "Reject". Each of the buttons has a specific ID … When any of the two are pressed, i would like to trigger an action in my controller. Below are the code snippets.

==============================================================================================================

View

<?php

echo CHtml::beginForm(‘mycontrollerName/AcceptUserRegistration’,‘get’);

?>

&lt;?php echo CHtml::submitButton('Accept', array('id' =&gt; 'accept')); ?&gt;


&lt;? echo '&amp;nbsp;&amp;nbsp;&amp;nbsp;'; ?&gt;


&lt;?php echo CHtml::submitButton('Reject', array('id' =&gt; 'reject')); ?&gt;    

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

==============================================================================================================

[b]Controller

[/b]

public function actionAcceptUserRegistration() {

    &#036;value = &#036;_GET['id'];


    


    if(&#036;value == &quot;accept&quot;){


        //will do something here


    }


    


    if(&#036;value == &quot;reject&quot;){


        //will do something here.


    }


   


}

=============================================================================================================

When i implement it this way. the get value in the controller side is empty. What I’m I doing wrong? Or is there any other way around this?

Regards

Yii-fan

make the button


<?php echo CHtml::submitButton('Accept', array('name' => 'button1')); ?>

<? echo '&nbsp;&nbsp;&nbsp;'; ?>

<?php echo CHtml::submitButton('Reject', array('name' => 'button2')); ?> 



and in Controller




public function actionAcceptUserRegistration() {


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

        {

        echo "Accept code here ";

        }

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

        {

        echo "Reject code here ";

        }


   	

    }



Try this

1 Like

[size=2]Goood stuff… Let me give it a try… and by the way, How does one specify the controller action it the Chtml::beginForm() params?[/size]

Try this


echo CHtml::beginForm( Yii::app()->createUrl('mycontrollerName/AcceptUserRegistration'),'post');

The first param can also be a route array, e.g.




echo CHtml::beginForm(array("mycontrollerName/AcceptUserRegistration"))



Thanks!

hi i used validation for the form fields… it also affect the cancel button what can i do for this pblm

Helped a lot …thank you

Im Newbie, and found this post

Thanks a lot, it helps me solve mine

It’s very useful.

Thanks a lot. It really helped me.

thanks alot… Helped me…