CGridView, textfield and button question

Hey guys,

I’m kind of stuck with this issue, looked around forums for a while and really couldn’t find any good solutions for this…

Here is my code


<?php $this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'columns'=>array(

      array(

        'class'=>'CLinkColumn',

        'header'=>'Product Name',

        'labelExpression'=>'$data->product->product_name',

        'urlExpression'=>'Yii::app()->createUrl("product/view", array("id"=>$data->id_product))',

      ),

      array( //TextBox --- Displays quantity

        'header'=>'Quantity',

        'value'=>'CHTML::activeTextField($data,\'quantity\')',

        'type'=>'raw',

        'htmlOptions'=>array('width'=>'40px'),

      ),

      array( //Update button - Doesn't work - nothing in post..

        'value'=>'CHTML::button(\'Update\',  array(\'submit\' => Yii::app()->createUrl("cart/update", array("id"=>$data->id_product))))',

        'type'=>'raw',

        'htmlOptions'=>array('width'=>'40px'),

      ),

      array( //Remove button - Works just fine

        'value'=>'CHTML::button(\'Remove\',  array(\'submit\' => Yii::app()->createUrl("cart/remove", array("id"=>$data->id_product))))',

        'type'=>'raw',

        'htmlOptions'=>array('width'=>'40px'),

      ),

    ),

)); ?>

Here is what i’m trying to do

When you hit update button it takes you to the right page, but my $_POST array is empty

I’m trying to make it so you change the number in textbox and hit update, you get re-directed and $_POST[] variable is = to the value of that textbox.

Anyone??

Try includind the CGridView in a form.

Exactly what I ended up doing:


<?php 


echo CHtml::beginForm();


$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'columns'=>array(

      array(

        'header'=>'Quantity',

        'value'=>'CHTML::textField($data->id_product,$data->quantity,array(\'width\'=>20,\'maxlength\'=>3))',

        'type'=>'raw',

        'htmlOptions'=>array('width'=>'20px'),

      ), 

      array(

        'class'=>'CLinkColumn',

        'header'=>'Product Name',

        'labelExpression'=>'$data->product->product_name',

        'urlExpression'=>'Yii::app()->createUrl("product/view", array("id"=>$data->id_product))',

      ),

      array(

        'header'=>'Price',

        'value'=>'($data->product->price)*($data->quantity)',

        'htmlOptions'=>array('width'=>'40px'),

      ),       

      array(

        'value'=>'CHTML::button(\'Remove\',  array(\'submit\' => Yii::app()->createUrl("cart/remove", array("id"=>$data->id_product))))',

        'type'=>'raw',

        'htmlOptions'=>array('width'=>'40px'),

      ),

    ),

));


echo CHTML::button('Update cart',  array('submit' => Yii::app()->createUrl("cart/update")));


echo CHTML::button('Checkout',  array('submit' => Yii::app()->createUrl("order/getInfo")));


echo CHtml::endForm(); 


?>



And did it work properly?

worked like a charm!

do you mind sharing your controller file as well wanna see how you saved it into the db

Kindly share you controller action.