Yii Framework Forum: Get A Value From A Submitted Form - Yii Framework Forum

Jump to content

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

Get A Value From A Submitted Form YII Framework Rate Topic: -----

#1 User is offline   sachi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 18-October 12

Posted 01 March 2013 - 04:02 PM

Hi, I'm new to YII Framework. What I'm trying to implement is Get a value of a dropdown function for another action to process a calculation.
First there is a form that has the dropdown,
<div class="form">
  <?php echo CHtml::beginForm('', 'POST'); ?>
    <?php echo CHtml::errorSummary($model); ?>
      <div class="row">
        <?php echo CHtml::activeLabel($model,'employeeID'); ?>
		<?php echo CHtml::activeDropDownList($model,'employeeID', CHtml::listData(Employee::model()->findAll(), 'employeeID','employeeID'), array('empty'=>'---Select one---')); ?>     
       </div>		
	 <div class="row submit">
       <?php echo CHtml::button('Submit', array('submit'=> array('salary/calsal'))); //  ?>	
     </div>	
      <?php echo CHtml::endForm(); ?>
</div><!-- form -->


Then in the other form I tried to get that selected value
	public function actionCal()
	{	
		$model=new Salary;
		$this->render('calc',array(
			'model'=>$model,
		));
	}
	
	public function actionCalsal()
	{	
		$id=$_POST['$model'];
		echo $id;
	}

this is the salary controller. first action sends $model to the above form. and second action tries to get the selected value from that form. but I always end up with getting this error. Undefined index: $model

Can someone please help me to do it properly. I have to implement it as a part of my Uni stuff. Thanks in advance! :)
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,694
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 01 March 2013 - 04:52 PM

View Postsachi, on 01 March 2013 - 04:02 PM, said:

$id=$_POST['$model'];


should be $_POST['Salary']['employeeID'] I suppose.
God is real unless declared as integer
1

#3 User is offline   macinville 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 268
  • Joined: 25-October 10
  • Location:Marikina City, Philippines

Posted 01 March 2013 - 08:39 PM

When using $_POST, you are getting the values from a form using the "name" attribute. So unless you have an input that has a name "$model", you won't get any value from $_POST["$model"]. ORey's answer might be correct, considering how Yii automatically creates a "name" attribute for every form input.
Tell your tail.
Don't be shy to upvote a post if it was able to help you
1

#4 User is offline   sachi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 18-October 12

Posted 01 March 2013 - 09:28 PM

View PostORey, on 01 March 2013 - 04:52 PM, said:

should be $_POST['Salary']['employeeID'] I suppose.

Thanks a lot ORey! It worked! :D And thanks macinville for confirming it. You guys are the best!
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