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 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 09-August 11

Posted 20 April 2012 - 02:19 AM

View PostKevin Kip, on 20 April 2012 - 01:52 AM, said:

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

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
0

#3 User is offline   Kevin Kip 

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

Posted 20 April 2012 - 02:33 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


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 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 09-August 11

Posted 20 April 2012 - 03:01 AM

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

1

#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

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