Changing Value Of Checkbox Column[Solved]

I’v been sitting on this for a couple of hours and searched through the forum with no success.

I’v done a basic mailer that gets addresses from a checkbox column and send them all some message.

I tried using ‘name’ or ‘value’ but the column is still sending the id instead of the email.

Here my code: (for debugging purpose I’v fixed the email address to mine , and the users’ addressed are going to the mail so that I’ll be able to see the change)


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

	'id'=>'test-person-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		array(         

				'class'=>'CCheckBoxColumn',

				'selectableRows' =>2,

				'value'=>'$data->email',     //should render the email instead of the id

			),

		'id',

		'name',

		'email',

	

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>


   <?php

	echo CHtml::button("send",array("id"=>"sender"));

	?>


	<?php

	Yii::app()->clientScript->registerScript('send','

	$("#sender").click(function(){

			var checked=$("#test-person-grid").yiiGridView("getChecked","test-person-grid_c0");

			var count=checked.length;

			if(count>0 && confirm(" do you want to send "+count+" message? "))

			{

					$.ajax({

							data:{checked:checked},                                                                   //can this cause the problem ? ? ?

							url:"'.CHtml::normalizeUrl(array('testPerson/sender')).'",

							success:function(data){$("#test-person-grid").yiiGridView("update",{});},              

					});

			}

			});

	');

	?>



and the controller:


public function actionSender()

	{

		 if(Yii::app()->request->getIsAjaxRequest())

        { 

                $checkedMails=$_GET['checked'];

                foreach($checkedMails as $message)

				{

					// $message = "This is a test mail from Mark Brass";

					// In case any of our lines are larger than 70 characters, we should use wordwrap()

					//$message = wordwrap($message, 70, "\r\n");

					mail('mark2bra@gmail.com', 'Test mail', $message);

				}


        }

		

			

		

	}

Now, the whole thing do work, but I get in my mail the users’ ids that I’v checked :(

Instead of ‘value’ I had tried ‘name’=>‘email’, but it didn’t work as well.

Cheers,

Mark.

Hi, try Setting value with htmlOptions Reference

Hello. You meant this?


'columns'=>array(

		array(        

				'class'=>'CCheckBoxColumn',

				'selectableRows' =>2,

				'checkBoxHtmlOptions'=>array('value'=>'$data->email'),     //should render the email instead of the id

			),

		'id',

		'name',

		'email',

I still get the id in the mail :(

It is the second day that I’m sitting on this single line. No success , I’m always getting the user’s id in my mails. :-[

How can it be that neither ‘name’ , nor ‘value’ are working? (I should write them under the array of the CchckboxColumn , right?)

The whole app works fine . . . but for id. I’v created an “opposite” app today (email is the Pkey) and tried to switch it to render the other data cell (which was id) , but it kept showing the Pkey only.

Any help will be much appreciated!

Thanks!

Cheers,

Mark.

3rd day , still no success.

I had the suspicion that the ajax I was using somehow overrided the ‘value’ , thus I used today another ajax


$.fn.yiiGridView.getChecked

, the app worked. . . . . but I still got the users’ ids in the mail . . . . :o

It looks like this line:


 'value'=>'$data->email',

simply doesn’t work in the CCheckBoxColumn

(though works in the CgridView , cause I managed to change the value displayed in the grid)

Now I don’t believe in goblins who dwell in the PC , but I have no idea why it doesn’t work.

Please help!

Can someone take a look at my code of the first app , or the second one I’ll post here and give some solution/advice :D


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

	'id'=>'mad-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

	array(        

				'id'=>'selectedIds',

				'class'=>'CCheckBoxColumn',

				'selectableRows'=>'2',

				 'value'=>'$data->email',		//the row that doesn't work

			),

                'id',

		'email',	

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>


<?php

     echo CHtml::ajaxLink('send', Yii::app()->createUrl('mad/sender'),

    array(

       'type'=>'POST',

       'data'=>'js:{selectedIds : $.fn.yiiGridView.getChecked("mad-grid","selectedIds")}'

    ));

	?>

and the controller (which is pretty much the same):


public function actionSender()

	{

		   if(isset($_POST['selectedIds'])){

        foreach ($_POST['selectedIds'] as $message){

					

					mail('mark2bra@gmail.com', 'Test mail', $message);

				}


        }

	}

Cheers,

Mark.

ok , on the forth day I was offered a solution - leave the id’s I get from the checkbox column , and with findByPk() method take out the emails from the users.

Here is the code:


 $checkedIds=$_GET['checked'];

                foreach($checkedIds as $id)

				{

					$message=TestPerson::model()->findByPk($id)->email;		

					mail('mark@gmail.com', 'Test mail', $message);