How to put glyphicon inside cakephp submit form? - php

The code:
<?php echo $this->Form->submit('<i class="glyphicon glyphicon-arrow-right"></i>', array('class' => array('btn btn-danger')), array('escape' => false)); ?>
Instead of glyphicon it shows just text:
<i class="glyphicon glyphicon-arrow-right"></i>
How to solve this?

As per the docs, you can't use escape with Submit- you have to use Button instead and specify that it's a submit button:
echo $this->Form->button('<i class="glyphicon glyphicon-arrow-right"></i>', array(
'type' => 'submit',
'class' => 'btn btn-danger',
'escape' => false
));

Form->submit() should take two options, a caption and an array of options. You are passing it the caption plus two arrays. Also I don't think in this case you need to wrap these options within sub-arrays.
Try this:
echo $this->Form->submit('<i class="glyphicon glyphicon-arrow-right"></i>',
array('class' => 'btn btn-danger', 'escape' => false)
);

Related

How to add icon class in PHP form_submit of Codeigniter

<?php echo form_submit(['type'=>'submit', 'class'=>'btn login-btn', 'name'=>'btnLogin', 'i class'=>'icon-long-arrow-right' , 'value'=>'Login']); ?>
How to display an icon on button in Codeigniter.I tried this but it didn't show icon on button.Where to make change so that icon will displayed on button?
$data = array(
'name' => 'button',
'id' => 'button',
'value' => 'true',
'type' => 'submit',
'class'=>'btn btn-primary btn-sm icon-cancel-circle2',
'content' => '<i class="icon-long-arrow-right"></i>'
);
echo form_button($data);
you can use this.Hope it helps.
try this
<?php echo form_submit('btnLogin', 'Login', '"class"="btn login-btn" "i class"="icon-long-arrow-right"'); ?
the first parameter is the name, second is the value of your button.

cakePHP 3.0 and bootstrap glyphicons

I want to add glyphicons instead of text in my index, add, edit views.
This works in the index.ctp
<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil"></i>'), ['action' => 'edit', $user->user_id], array('escape' => false)) ?>
But when I do it for the delete action it shows me the glyphicon but it doesn't give me the 'Are you sure you want to delete the user?' anymore
<?= $this->Form->postLink(__('<i class="glyphicon glyphicon-minus"></i>'), ['action' => 'delete', $user->user_id], array('escape' => false), ['confirm' => __('Are you sure you want to delete {0}?', $user->username)]) ?>
In the view.ctp it breaks the code that comes after so the content that comes after isn't shown. (in this example that's the content after the glyphicon-pencil. The glyphicon-pencil itself isn't shown as well.
<?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil'), ['action' => 'edit', $user->user_id], ['escape' => false]) ?>
Take a closer look at the arguments that you are passing, you are passing 4, where the method only accepts 3, ie the confirm option is not passed in the actual options argument.
Proper formatting helps a lot to spot such mistakes.
<?=
$this->Form->postLink(
__('<i class="glyphicon glyphicon-minus"></i>'),
[
'action' => 'delete',
$user->user_id
],
[
'escapeTitle' => false,
'confirm' => __('Are you sure you want to delete {0}?', $user->username)
]
)
?>
And your FormHelper::link() example is missing a closing double quote for the <i> elements class attribute, as well as a closing tag for the element itself:
'<i class="glyphicon glyphicon-pencil"></i>'
Also you may want to use escapeTitle instead of escape, in order to avoid disabling escaping for attributes too.

yii2: How to work with font awesome icons?

I have this HTML link tag that I need to generate using yii\helpers\Html
<i class="fa fa-fw fa-user"></i> Sign Up
I am able to do it using method a() but I do not know how to include the font awesome class. Here is the code that I already have using a() method
<?= Html::a('Sign Up',['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
I am using bootstrap for my CSS. Any help would be appreciated.
It's simple
<?= Html::a('<i class="fa fa-fw fa-user"></i> Sign Up',['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
Following code generate your desired HTML.
<?= Html::a(Html::tag('i', '', ['class' => 'fa fa-fw fa-user']) . ' Sign Up ', ['site/signup'], ['class' => 'btn btn-black', 'title' => 'Sign Up']) ?>
You can also use yii2-icons, see: https://github.com/kartik-v/yii2-icons
At first you have to install the extension:
composer require kartik-v/yii2-icons "#dev"
Then you can display the icons e.g. in the following way:
use kartik\icons\Icon;
...
Icon::show('trash', ['title' => 'delete'])
Icon::show('calendar', ['class'=>'fa-2x'])
You can find more examples on this demopage: http://demos.krajee.com/icons

How can i add a icon to submit button Yii?

Html button is
<button class="btn" type="submit"><i class="icon-search"></i> Go</button>
I changed it into Yii as
<?php
echo CHtml::submitButton('Go', array('id' => 'btSubmit',
'class' => 'btn',
'name' => 'files'
));
?>
How can i add to button
This will work
echo CHtml::tag('button', array(
'name'=>'btnSubmit',
'type'=>'submit'
), '<i class="icon-search"></i> Go');
will generate
<button name="btnSubmit" type="submit"><i class="icon-search"></i> Go</button>
According to the yii source code the CHtml::tag method requires a third parameter to submit internal content. The CHtml::button method does not pass this through, so you can't add internal HTML.
Using the tag method directly should work however:
echo CHtml::tag('button',[
'id'=>'btsubmit','class'=>'btn','name'=>'files','type'=>'submit'
],'<i class="icon-search"></i> Go');
<?php echo CHtml::submitButton(
CHtml::tag('i', array('class' => 'icon-search')) . ' Go',
array('id' => 'btSubmit',
'class' => 'btn',
'name' => 'files')
);
?>
Use CHtml::tag('i', array('class' => 'icon-search')) . ' Go' instead of 'Go' in your code.

How to include a css class that is an image on codeigniter form submit?

<?php
$data = array(
'class' => "btn btn-primary btn-lg",
'name' => 'report'
);
echo '<span class="glyphicon glyphicon-exclamation-sign"></span> ';
echo form_submit($data, 'Report');
$data = array(
'class'=>"btn btn-primary btn-lg",
'name' => "search"
);
echo anchor("",'<span class="glyphicon glyphicon-search"></span> Search',$data);
echo form_close();
?>
I want to include <span class="glyphicon glyphicon-exclamation-sign"></span> on the form_submit. This span class is an image, I cant find a way to put it inside the button.
http://puu.sh/6UbE8.jpg
The second one "echo anchor", its second parameter has a span class which is also an image followed by a word "Search". This is exactly what I want the previous "form_submit" to be looks like. http://puu.sh/6UbFt.png
Use form_button instead of form_submit, and wrap your span around label.
$data = array(
'class' => "btn btn-primary btn-lg",
'name' => 'report'
);
echo form_button($data, '<span class="glyphicon glyphicon-exclamation-sign">Report</span>');
hope it will help
$data = array(
'name' => 'report',
'id' => 'report',
'value' => 'true',
'type' => 'submit',
'class' => 'btn btn-primary btn-lg'
);
echo form_button($data);
you can check http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html

Categories