ryuuuuuusei
ryuuuuuusei

Reputation: 108

passing a variable using chmtl text field and button

I'm trying to create a text box and a button. when the button is pressed, the input in the text box is passed to the next view. so far, I've been only able to write this:

echo CHtml::textField('text'); 
echo CHtml::button('Submit',array('submit' => array('site/result')));

which is pretty much just a plain button and text field. any help on what should i add to my code? and also, how do i retrieve a passed data in the other view?

Upvotes: 1

Views: 264

Answers (1)

Manquer
Manquer

Reputation: 7647

Modify your view code like this

<?php 
  $this->beginWidget("CActiveForm",array(
       'id'=>'new_view_action',
       'action'=>array('site/result')
   ));
        echo CHtml::textField('text'); 
        echo CHtml::button('Submit',array('submit' => array('site/result')));
  $this->endWidget();
?>

In your Site Controller Result action

class SiteController extends CController {
....
     public function actionResult(){
         if(isset($_POST['text'])){
          $text = $_POST['text'] ;
          // Do logic based on text value 

          $this->render('secondView',array('attributes'=>$attributes));

         }
    }
}

Upvotes: 1

Related Questions