Chtml link

Hi Friends,

I need to pass form field values to Chtml link . I have tried in the below mentioned way but it did not work out. Just i am getting the statement itself instead of field value. Am i doing in the right way ? Looking for suggestions. Even i have tried by adding “js:” in front but it’s not working.

Thanks in advance.





echo CHtml::link('Add Trip Details', Yii::app()->createUrl("driverwagescal/internaldriver/TempIntTripDetails/create",array(


						'test'=>'$("#'.CHtml::activeId($int_trip_details_model,'transport_code').'").val()',

				

			

				)

				

				); 




Any help ?

Newbie here.

I have a similar problem.

I wish to POST a form on a page using a CButton or any other column type in a CGridView but the parameters for the post come from the grid columns. I am trying to use htmlOptions but $data is not accessible. I thought this would be easy but I’m having a hard time at this.

Thanks in advance.

Is this the one you are looking for ?





array(

				

					'class'=>'CButtonColumn',

					'htmlOptions' => array('style'=>'width:120px'),

		 	  		'template'=>'{view}{update}',

		    		'buttons'=>array

    				(

       		  			'view' => array

       		   			(

            	 			'label'=>'View Summary Page',

            	 			'imageUrl'=>Yii::app()->request->baseUrl.'/images/view.png',

            	 			'url'=>'Yii::app()->createUrl("/driverwagescal/externaldriver/extDriverWagesRec/view", array("id"=>$data->id))',

            	 			'options'=>array('target'=>'_blank'),

            	 			


       		   			

       		   

       		 			),

       		 			

       		 					       		 	

		       		 	'update' => array

		       		   (

		            	 'label'=>'Amend Wages Records',

		            	 'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',

		            	 'url'=>'Yii::app()->createUrl("/driverwagescal/externaldriver/extDriverWagesRec/update", array("id"=>$data->id))',

		            	 'visible'=>'$data->status == 1',

		       		   

		       		 	),

		       		 	

		       		 )

		       		), 	

		




Hello there,

Thanks for responding. I don’t think so. I need to POST the form but the grid is not supplying POST information when using the CButton click.

I have tried just about anything I could find from the forum and class ref docs.

Perhaps I am missing something obvious but I am a newb.

Thanks.

Just a note: I see you can call a JS from the click option for CButton definition. My JS is slim and far from none.

I tried to make an alert with data from a column but that did not work as well. Perhaps its my lack there of but if I could get a JS function to get column data I could call a JS Document.form_id.submit function, no ?

Progress,


'click'=>"function(){alert( $(this).parent().parent().children(':first-child').text() );}",

Got this from another post; if I had some docs for the grid class I could perhaps get the info I require. Right now the first hidden column I have is not being retrieved.

Still trying…

If anyone can help on this one; much appreciated.

:(

Solved!!!!!

With help from here, and a bunch of others. Would not have got this without this post so hats off to those of the post.

Post

This is how I did it.

First, make a virtual attribute in your model to concat a custom URL you would normally have in a button column url.




private $_update_url=NULL;                


public function getupdate_url()        

{             

   $url = "";             

   if(!isset($this->_update_url))             

   {              

     $url = Yii::app()->createUrl('client/updateDonation', 

              array('id'=>$this->client_id,  'donation_id'=>$this->id)); 

     $this->_update_url = $url;             

   }            

   return $this->_update_url;                     

}        

public function setupdate_url($value)        

{            

   $this->_update_url = $value;        

}

Then in your grid add this column and hide it easy enough with CSS. The visible property did not work for the column when using the JS function of the Click event.

So here is the button and column. Notice the :nth-child([font="Arial Black"]3[/font]) More specifically the number 3. This is the column where you have your URL. Also in the column you will have to add a class for hiding the td which is not assigned in the grid by default.




array(                  

   'name'=>'update_url',

   'header'=>'',

   'htmlOptions'=>array('class'=>'hide_this_column'),

),                

array('class'=>'CButtonColumn',

        'template'=>'{update}',

        'buttons'=>array(

            'update'=>array( 

                 'label'=>'Update',                           

                  'url'=>'"#"',                            

                  'click'=>'function(){ document.forms.client_form.action=$(this).parent().parent().children(":nth-child(3)").text(); document.forms.client_form.submit();}'                        

                   ),

),),



Here is my CSS to hide the header and also to reference the htmlOptions above in the grid column holding the url. Firebug does come in handy. I am assuming that the column could be hidden another way, but this is working for me.

#client-donations-grid_c3

{

display: none;

}

.hide_this_column

{

display: none;

}

So with the virtual column that is hidden I can now use the CGridView to POST my form with specific column information to a specific controller action. Hurray!!!

Please post back if you do have another option but I could not find any. Hope this helps someone else and saves them some time.

Thanks

Any help ?