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.
Related
<?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.
I am having a problem with modal window loading on staging server. Where my modal windows load on localhost (Apache) they fail to load content on staging (LiteSpeed). What is strange is that the modal opens and shows header, but no content. I get 503 error when I inspect elements.
Staging also doesn't load favicon. I suppose the problem is somewhere in configuration, but as I am just starting with Yii2, I don't know where to look anymore.
I have created the modal functionality as follows:
modal.js in web/js/modal.js
$(function(){
$(document).on('click', '.showModalButton', function(){
if ($('#modal').data('bs.modal').isShown) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
//dynamically set the header for the modal
document.getElementById('modalHeader').innerHTML = '<button type="button" class="close" ' +
'data-dismiss="modal" aria-label="Close">' +
'<span aria-hidden="true">×</span>' +
'</button> ' +
'<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
//dynamically set the header for the modal
document.getElementById('modalHeader').innerHTML = '<button type="button" class="close" ' +
'data-dismiss="modal" aria-label="Close">' +
'<span aria-hidden="true">×</span>' +
'</button> ' +
'<h4>' + $(this).attr('title') + '</h4>';
}
});
});
Layout set in views/layouts/main.php (excerpt)
</footer>
<?php
Modal::begin([
'headerOptions' => [
'id' => 'modalHeader',
],
//'footer' => 'Close',
'id' => 'modal',
'size' => 'modal-lg',
//keeps from closing modal with esc key or by clicking out of the modal.
// user must click cancel or X to close
'clientOptions' => [
'backdrop' => 'static',
'keyboard' => false
],
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<?php $this->endBody() ?>
View for index action (excerpt)
<p>
<?= Html::a('Create FAQ',
false,
[
'class' => 'showModalButton btn btn-success',
'value' => '/index.html?r=faq/create',
'title' => 'Create FAQ',
]) ?>
</p>
When I press button modal opens,but doesn't load the form.
If I missed some important information, please ask if it can shed light to this issue.
The page loads all the assets and I get the 503 error only on staging server.
use yii\bootstrap\Modal;
in your Grid View
'panel' => [
'before' => Html::a('<i class="glyphicon glyphicon-plus">Open Modal</i>', ['#'], ['data-toggle' => 'modal', 'class' => 'btn btn-md btn-success', 'data-target' => '#showModal']),
'type' => GridView::TYPE_PRIMARY,
]
At the bottom add this
Modal::begin([
'id' => 'showModal',
'header' => '<center><h4 class="modal-title">Allocate Work </h4></center>',
'closeButton' => [
'label' => 'Close',
'class' => 'btn btn-danger btn-sm pull-right',
],
]);
echo Yii::$app->controller->renderPartial('allocation');
Modal::end();
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)
);
<?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
I have a simple delete function. Here is where I set the custom data:
<?php echo $this->Html->link(
__('Delete'),
'#CoursesModal',
array(
'class' => 'btn-remove-modal',
'data-toggle' => 'modal',
'role' => 'button',
'data-uid' => $course['Course']['id'],
'data-uname' => $course['Course']['name']
));
?>
It shows in the element fine:
Delete
But when it comes to deleting this object (here's the code for it:)
<?php echo $this->Html->link(__('Delete'),'/courses/delete/#{uid}',array('class' => 'btn btn-danger delete-course-link')) ?>
For some reason the {uid} doesn't translate to 5 - which causes it not to work.
What am I doing wrong?