Alimon Karim
Alimon Karim

Reputation: 4469

cakephp 3 : How to add class in form button?

I have tried this line to add class in cakephp form button, but class is not showing in html

<?= $this->Form->button(__('Login',['class'=>'login-btn'])); ?>

How can I add class in button ?

Upvotes: 3

Views: 5924

Answers (3)

vins
vins

Reputation: 539

it has to be inside an array : try this

<?= $this->Form->button(__('Login'),array('class'=>'login-btn')); ?>

Upvotes: 0

mario.van.zadel
mario.van.zadel

Reputation: 2949

I think your example doesn't work, because the __() Call shouldn't include the array for the options of the button. Please try the following:

<?= $this->Form->button(__('Login'),['class'=>'login-btn']); ?>

Upvotes: 11

Robin Carlo Catacutan
Robin Carlo Catacutan

Reputation: 13679

Have a try on this below:

<?php echo $this->Form->button('Login',['class'=>'login-btn']); ?>

A good reference here: Creating input elements

Update

__() is for internalization. Using this will look in to your localization file and output it's corresponding translation. In your case, you include the options inside __() which I think it will cause an error but if it didn't, it will look for it's translated version and also this means ['class'=>'login-btn'] is not considered as an option anymore.

Upvotes: 1

Related Questions