Add html element inside of form element using cake php form helper

大城市里の小女人 提交于 2019-12-08 01:38:26

问题


I am trying to create a simple html output that looks like this

<button class="searchbutton" id="search_button" type="submit">-->
      <i class="icon-search"></i> Search</button>

with Cake php's form helper, i cant figure out why the 'after' attribute doesn't add the inner <i> </i> html element.

This is what i have tried.

  echo $this->Form->button('Search', array('type' => 'submit','id' => 'search_button','class' => 'searchbutton',
        'after' => "<i class='icon-search'></i>"));

回答1:


You just include the extra <i></i> tag in the button $title, also include 'escape' => false to ensure the mark up is not escaped, even though is not escaped by default as on v3.1.1, this may change in future, who knows..

Example:

echo $this->Form->button("<i class='icon-search'></i> Search", array('type' => 'submit','id' => 'search_button', 'class' => 'searchbutton', 'escape' => false));



回答2:


Please try below code.

echo $this->Form->button('Search', array('type' => 'submit','id' => 'search_button','class' => 'searchbutton','escape' => true,
        'after' => "<i class='icon-search'></i>"));



回答3:


see this

echo $this->Form->button('Search', array('type' => 'submit','id' => 'search_button','class' => 'searchbutton','escape' => true, 'after' => "<i class='icon-search'></i>"));



来源:https://stackoverflow.com/questions/14016966/add-html-element-inside-of-form-element-using-cake-php-form-helper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!