Design Elamm
Design Elamm

Reputation: 1

CakePHP Add HTML in field options

I try to recreate this menu in html to cakephp form, but i don't know how can i put the icon in the options...

<div class="ui fluid label dropdown">
    <i class="dropdown icon"></i>
    <span class="default text">Filter by</span>
    <div class="menu">
        <div class="item" data-value="0">With Comments<i class="comments right floated icon"></i></div>
        <div class="item" data-value="1">Without Comments<i class="comments outline right floated icon"></i></div>
        <div class="item" data-value="2">With Attachment<i class="attach right floated icon"></i></div>
        <div class="item" data-value="3">Without Attachment</div>
    </div>
</div>

This is my CakePHP code:

echo $this->Form->input('field',
        array(
           'options' => array('With Comments', 'Without Comments','Without Attachment'), 
           'empty' => 'Filter by', 
           'class' => 'ui dropdown', 
           'onchange' => 
           'submitForm()', 
           'name' => 'FB'));

Upvotes: 0

Views: 525

Answers (1)

Chris Vogt
Chris Vogt

Reputation: 1199

You may wish to review the FormHelper documentation to verify you are properly using the helper.

The select input type allows for a special $option attribute called 'escape' which accepts a bool and determines whether to HTML entity encode the contents of the select options. Defaults to true:

$options = [
  'M' => 'Male <i class="fa fa-man"></i>',
  'F' => 'Female <i class="fa fa-woman"></i>'
];
echo $this->Form->select('gender', $options, ['escape' => false]);

(Adapted from the documentation.)

Upvotes: 1

Related Questions