CakePHP: How to Use HTML Objects in Button Titles with Form Helper

I would like to use a check mark as the text for a button. The entity I want is this ✓

, but when I put it as text for a button using the Form Helper, it always converts the leading ampersand to &

so that the text shows, but not the entity.

This is how I create the button:

echo $this->Form->button(
    '✓', 
    array(
        'type' => 'submit', 
        'id' => $checklistItem['ChecklistItem']['id'], 
        'escape' => 'false'
    )
);

      

and the generated HTML looks like this:

<button type="submit" id="1">&amp;#x2713;</button>

which obviously doesn't render the object.

I tried this by installing 'escape' => 'true'

but it had no effect at all.

Any ideas?

+3


source to share


2 answers


You don't need to escape this false, it defaults to false.



  echo $this->Form->button('&#x2713;',  
          array(
               'type' => 'submit', 
               'id' => $checklistItem['ChecklistItem']['id']
           )
  );

      

+3


source


You need to move your escape to the third element of the button:

echo $this->Form->button(
    '&#x2713;', 
    array(
        'type' => 'submit',
        'id' => $checklistItem['ChecklistItem']['id'], 
    ),
    array('escape' => 'false')
);

      



Also, this has already been answered here .

0


source







All Articles