Yii Framework Forum: Two submit buttons , one form - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Two submit buttons , one form working with more than one CHtml::submit() in a CHtml::beginForm() Rate Topic: -----

#1 User is offline   Kevin Kip 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-April 12

Posted 20 April 2012 - 01:52 AM

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');
?>

<?php echo CHtml::submitButton('Accept', array('id' => 'accept')); ?>
<? echo '&nbsp;&nbsp;&nbsp;'; ?>
<?php echo CHtml::submitButton('Reject', array('id' => 'reject')); ?>
<?php echo CHtml::endForm(); ?>

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

Controller

public function actionAcceptUserRegistration() {

$value = $_GET['id'];

if($value == "accept"){
//will do something here
}

if($value == "reject"){
//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
0

#2 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 20 April 2012 - 02:19 AM

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
3

#3 User is offline   Kevin Kip 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-April 12

Posted 20 April 2012 - 02:33 AM

Goood stuff.... Let me give it a try.. and by the way, How does one specify the controller action it the Chtml::beginForm() params?
1

#4 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 20 April 2012 - 03:01 AM

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

2

#5 User is offline   phpnode 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 18-April 11

Posted 22 April 2012 - 01:54 PM

View PostBalu, on 20 April 2012 - 03:01 AM, said:

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"))

1

#6 User is offline   Scott Gardner 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 03-May 13

Posted 05 July 2013 - 07:51 PM

View PostBalu, on 20 April 2012 - 02:19 AM, said:

and in Controller
public function actionAcceptUserRegistration() {

        if(isset($_POST['button1']))
        {
        echo "Accept code here ";
        }
      if(isset($_POST['button2']))
        {
        echo "Reject code here ";
        }

       
    }

Try this


Thanks!
0

#7 User is offline   Karthiga Nathan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 02-September 13

Posted 16 September 2013 - 06:53 AM

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

#8 User is offline   Yii coder 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 12-September 13

Posted 04 October 2013 - 06:13 AM

View PostBalu, on 20 April 2012 - 02:19 AM, said:

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


Helped a lot ......thank you
0

#9 User is offline   had 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 03-July 12
  • Location:Bandung

Posted 31 March 2014 - 11:59 PM

Im Newbie, and found this post
Thanks a lot, it helps me solve mine
0

#10 User is offline   chriscao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 03-February 10

Posted 09 April 2014 - 02:57 AM

It's very useful.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users