2014-08-28 44 views
0

我遇到了在表單元素的標籤中顯示html的問題。包含html字符的Magento字段標籤

下面是代碼:

question-
$fieldset->addField($season->getId()."_".$question->getId(), 'checkboxes', array(
        'name' => $season->getId()."_".$question->getId(), 
        'label' => $question->question, 
        'title' => $question->question, 
        'class' => 'season-questions '.$season->getId(), 
        'values' => $options, 
        'value' => '' 
       )); 

目前$>的問題有時會包含HTML字符,如

<p><strong>text</strong></p> 

在瀏覽器中顯示時,這是剛剛呈現爲字符串。

如何讓html正確顯示?我曾嘗試:

getEscapedValue() 

toHtml() 

無濟於事。

+0

是什麼'$ question-> question'? – 2014-08-28 17:39:34

+0

它是字符串類型 – Panda4Man 2014-08-28 17:51:12

回答

0

爲了移除html元素,您可以使用strip_tags()。所以試試這個。

$fieldset->addField($season->getId()."_".$question->getId(), 'checkboxes', array(
    'name' => $season->getId()."_".$question->getId(), 
    'label' => Mage::helper('your_helper_alias')->__(strip_tags($question->question)), 
    'title' => Mage::helper('your_helper_alias')->__(strip_tags($question->question)), 
    'class' => 'season-questions '.$season->getId(), 
    'values' => $options, 
    'value' => '' 
)); 

希望它可以幫助

+0

我試過strip_tags作爲一個計劃B工作正常,但客戶希望能夠通過豐富的文本字段使文本加粗等。那麼,有沒有一種方法來正確呈現html,或者我只需要去掉標籤? – Panda4Man 2014-08-28 18:03:08

+0

你可以把'style'=>'somestyles'或定義一些css來定義類 – 2014-08-28 18:07:21

相關問題