Passing Form Data And Cgridview Data Simultaneously

I have a view having a single CHTML text field and a TbExtendedGridView. Selected rows from the tbExtendedGridView along with the text field data are to be submitted to the database. It is a batch addition process where each row along with the textfield data is one record.

I can get the selected rows using the js function js:{chk:$.fn.yiiGridView.getSelection(‘gridname’)}. How can I pass the textfield data along with the selected row data in the CHTML submit button.

View File:

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(

'id'=&gt;'client-account-create-form',


'enableAjaxValidation'=&gt;false,

)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;


		


&lt;div class=&quot;row&quot;&gt;


    &lt;?php echo &#036;form-&gt;labelEx(&#036;model,'formname'); ?&gt;


    &lt;?php echo &#036;form-&gt;textField(&#036;model,'formname'); ?&gt;


    &lt;?php echo &#036;form-&gt;error(&#036;model,'formname'); ?&gt;


&lt;/div&gt;


&lt;div class=&quot;row&quot;&gt;


  &lt;?php


    &#036;this-&gt;widget('bootstrap.widgets.TbExtendedGridView', array(           


        'type'=&gt;'striped bordered condensed',          


        'id'=&gt;'grsubfielddata',


        'fixedHeader' =&gt; true,


        'headerOffset' =&gt; 40,             


        


        'dataProvider' =&gt; new CActiveDataProvider('Subfields',array(


           'criteria'=&gt;array(                      


                'order'=&gt;'tagno, slno',),                      


                'pagination'=&gt;array('PageSize'=&gt;20,), )),         


        'enablePagination' =&gt; TRUE,            


       


        'selectableRows'=&gt;2,


                'pager' =&gt; array(


                'cssFile' =&gt; false,


                'header' =&gt; false,


                'firstPageLabel' =&gt; 'First',


                'prevPageLabel' =&gt; 'Previous',


                'nextPageLabel' =&gt; 'Next',


                'lastPageLabel' =&gt; 'Last',),       


                           


       'template'=&gt;&quot;{pager}&#092;n{items}&#092;n{pager}&quot;,


        'columns' =&gt; array(


            array(


                      'class'=&gt;'CCheckBoxColumn',   


                      'id'=&gt;'chk',


            ),


            'tagno','fieldcode','fieldname'),


    


        


    ));


 ?&gt;


&lt;/div&gt;


       





&lt;div class=&quot;row buttons&quot;&gt;


    &lt;?php echo CHtml::submitButton('orgSubmit',  array(&quot;data&quot; =&gt; &quot;js:{chk:&#036;.fn.yiiGridView.getSelection('grsubfielddata')}&quot;)); ?&gt;


&lt;/div&gt;

<div>

</div>

<?php $this->endWidget();?>

</div><!-- form -->

There is very nice article on Batch Processing, here is the link might help you

http://www.yiiframework.com/wiki/353/working-with-cgridview-in-admin-panel/

Thanks for the response

There were a few problems which I could solve

  1. How to convert the selected rows from the gridview to string

Solution: wrote a Javascript and converted the selected rows to string and assigned it back to a hidden field.

  1. Single assignment was not possible as there was a syntax error

as i was using only

$frm=>$_POST[fieldname] instead of

$frm=>$_POST[Modelname][fieldname]

Not yet solved:

I could now pass all the records from the view to the Controller (which I can print using echo) but only the last record is getting added to the database.