Yii Framework Forum: CGridView removes/strips HTML - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView removes/strips HTML Rate Topic: -----

#1 User is offline   tomsea 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 25-November 11

Posted 27 January 2012 - 11:06 AM

Hello everyone. I'm using a CGridView with a data provider (CArrayDataProvider) and it's working fine, but, one of the columns content is a link that it's not working and I would appreciate your help to troubleshoot this issue.

The CGridView definition is like this:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        array(            
            'name'=>'column1',
            // call the method 'getLink' from a model.
            'value'=>array($model, 'getLink'), 
            'type'=>'html',
        ),
    ),
));


The function in the model, is defined like this:

public function getLink($data, $row)
{
	return CHtml::beginForm() . CHtml::hiddenField("param1", $data["param1"]) . CHtml::linkButton($data["param1"], array("submit"=>array("customview2"))) . CHtml::endForm();
}


Everything seems to be working fine except for one thing. If I set 'type'=>'text' in the CGridView column, the "HTML text" is displaying as expected, like:

<form action="/webapp/customview1" method="post"><input type="hidden" value="700" name="param1" id="param1" /><a href="#" id="yt1">700</a></form>


But, if I set 'type'=>'html' in the CGridView column, the rendered HTML is displaying only the link. Checking the page source code shows this:

<a href="#">700</a>


and of course, the link doesn't work because it doesn't have the required html form tags.

From what I see, the CGridView is striping out the form HTML tags, maybe because as a security feature, in which case I don't understand why it's doing that when I am specifying that it is an "html" column.

I would really appreciate all your ideas to solve this "mistery".

Thank you in advance!

Edit: I just made a simpler test, and if I set the "value" of the column to be just:

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        array(            
            'name'=>'column1',
            'value'=>'"<form><b>Hello</b></form>"',
            'type'=>'html',
        ),
    ),
));


The page outputs only "<b>Hello</b>" (displays Hello in bold, but the other tags are missing)... what is happening with the other tags? How can I stop this behavior? How can I use any tags that I want there?

Thank you!
0

#2 User is offline   tomsea 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 84
  • Joined: 25-November 11

Posted 27 January 2012 - 11:11 AM

Ok, after a couple hours of troubleshooting this, the solution is to specify the column type as "raw":

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
        array(            
            'name'=>'column1',
            // call the method 'getLink' from a model.
            'value'=>array($model, 'getLink'), 
            'type'=>'raw',
        ),
    ),
));


Everything is now working as expected. I hope this helps someone in the future!
0

#3 User is offline   bbunlock 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 20-May 12

Posted 03 June 2013 - 11:39 AM

thank you, I was having the same problem of links not showing and your info solved it for me.

again thanks :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users