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 ' '; ?>
<?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
Page 1 of 1
Two submit buttons , one form working with more than one CHtml::submit() in a CHtml::beginForm()
#2
Posted 20 April 2012 - 02:19 AM
Kevin 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 ' '; ?>
<?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
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 ' '; ?>
<?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 ' '; ?>
<?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
Posted 20 April 2012 - 02:33 AM
Balu, on 20 April 2012 - 02:19 AM, said:
make the button
and in Controller
Try this
<?php echo CHtml::submitButton('Accept', array('name' => 'button1')); ?>
<? echo ' '; ?>
<?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?
#4
Posted 20 April 2012 - 03:01 AM
Try this
echo CHtml::beginForm( Yii::app()->createUrl('mycontrollerName/AcceptUserRegistration'),'post');
Share this topic:
Page 1 of 1

Help











