2
votes

I am trying to insert a Font Awesome icon in a submit button using CakePHP and Twitter Bootstrap 3.

Here is the code:

echo $this->Form->submit('Send', array('class' => 'btn btn-warning fa fa-envelope', 'escape' => false));

It works for regular buttons, but for the input that which is generated by the FormHelper above, it does not render with an icon. Can I tweak FormHelper::submit to solve this?

I could use other types of FormHelper buttons, but the CakePHP docs explicitly states that:

Try to avoid using FormHelper::input() to generate submit buttons. Use FormHelper::submit() instead.

1

1 Answers

8
votes

You can just use:

echo $this->Form->button('<i class="fa fa-envelope"></i> Send', array(
    'type' => 'button',
    'class' => 'btn btn-warning fa fa-envelope',
    'escape' => false
));

I don't think the quote you listed is to keep you from doing this, but it should probably be clarified.

Bottom line, if it generates the correct HTML, then it's fine. But - to it's point, using button or submit instead of `input (so it doesn't have a value that's submitted) is the way to go.

http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::button