CakePHP - FormHelper not outputting form tags - html

I have the following form declaration:
<div class="edit-dialog span-10" style="display:none;">
<div class="edit-message span-10" style="margin-bottom:30px;">
<span>Editing: <a style="text-decoration:none"></a></span>
</div>
<?php
echo $this->Form->create('Voicenote', array('action' => 'edit'));
echo $this->Form->input('title', array(
'div' => false,
'class' => 'input-text recorder',
'label' => array(
'class' => 'inlined',
'text' => ''
),
'id' => 'VoicenoteEditTitle',
'placeholder' => 'Title',
'style' => 'margin-bottom:10px;',
'onsubmit' => 'return false;'
));
echo $this->Form->input('tags', array(
'div' => false,
'class' => 'input-text recorder',
'id' => 'VoicenoteEditTags',
'label' => false,
'placeholder' => 'Tags',
'onsubmit' => 'return false;'
));
echo $this->Form->button('Cancel', array(
'class' => 'button medium blue',
'id' => 'cancel-edit',
'style' => 'float:left;margin-top:50px;'
));
echo $this->Form->submit('Save', array(
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
?>
<input type="hidden" id="edit-container-index" value="">
</div>
It's not outputting the <form></form> tags and I have declared my forms this way throughout my app, adding the $this->Form->end() doesn't work either, any clues?
EDIT: explicitly declaring the <form></form> tags does not output them either
EDIT 2: there is something really weird I'm noticing. I have 4 forms on the page with the problem, If I remove the rendering of the element with the problem, another one of my forms wont render, the one right after it.

you have a submit button. just add end() after submit button in your ctp file.
<?php
echo $this->Form->create('users');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit('login');
echo $this->Form->end();
?>

Hi I think if you change last echo to
echo $this->Form->end( array(
'label'=>'Save',
'class' => 'button medium blue',
'id' => 'save-edit',
'style' => 'float:right;margin-top:50px;'
));
it should work

Related

How to render another controller method by image link using yii2?

following code will render an image:
<?= Html::img('#web/img/accept_all_you_see-wallpaper-1680x1050.jpg', ['alt' => 'PicNotFound', 'class' => 'scale-with-grid wp-post-image', 'style' => 'width:960;height:700']); ?>
following code will render an image as a link
<?= Html::a('', Yii::getAlias('#web') . '/img/pic1.jpg', ['target' => '_blank', 'alt' => 'PicNotFound', 'class' => 'icon-search']) ?>
How to code, if I want render another Conroller method by clicking on an image?
Following code will implement my intention by bootstrap icon, not by image!
<div class="col-md-12">
<?= Html::a('<span class="glyphicon glyphicon-paperclip"></span>', ['/dateianhang/dateianhang/index'], ['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]); ?>
</div>
<?= Html::a(
Html::img(
'#web/img/accept_all_you_see-wallpaper-1680x1050.jpg',
['alt' => 'PicNotFound', 'class' => 'scale-with-grid wp-post-image', 'style' => 'width:960;height:700']
),
['/dateianhang/dateianhang/index'],
['title' => 'Anlagen anzeigen', 'data' => ['pjax' => '0']]
) ?>

yii2 - two modal in one active form

I have 2 modals in one active form. Let's say first one is modal-ticket and second one is contract-ticket. First time, I click button to show modal-ticket, and it was fine, but when I click button to show modal-contract, it also call script modal-ticket or otherwise. why?
this is my code.
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalTicketList',
'data-toggle'=>"modal",
'data-target'=>"#modalTicketList",
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalContractList',
'data-toggle'=>"modal",
'data-target'=>"#modalContractList",
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'header' => 'Ticket List',
'id' => 'modalTicketList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentTicket'></div>";
Modal::end();
?>
<?php
Modal::begin([
'header' => 'Contract List',
'id' => 'modalContractList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentContract'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$('#BtnModalTicketList').click(function(e){
e.preventDefault();
$('#modalTicketList').modal('show')
.find('#modalContentTicket')
.load($(this).attr('value'));
return false;
});
$('#BtnModalContractList').click(function(e){
e.preventDefault();
$('#modalContractList').modal('show')
.find('#modalContentContract')
.load($(this).attr('value'));
return false;
});
JS;
$this->registerJs($script);
?>
this are the error found in console web browser
GET http://localhost/pks/web/ticket-timbangan/get-ticket?id=1 404 (Not Found)
GET http://localhost/pks/web/contract/get-contract?id=2 404 (Not Found)
please help.
Try This: using one modal on your form:
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary showModal',
'id' => 'BtnModalTicketList',
'title' => 'Search Ticket',
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary showModal',
'title' => 'Search Contract',
'id' => 'BtnModalContractList',
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'modal',
'size' => 'modal-lg',
'closeButton' => [
'id'=>'close-button',
'class'=>'close',
'data-dismiss' =>'modal',
],
'class' => 'style=width:auto',
'clientOptions' => [
'backdrop' => false, 'keyboard' => true
]
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$(document).on('click', '.showModal', function(){
if ($('#modal').hasClass('in')) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
}
});
JS;
$this->registerJs($script);
?>
From viewing your code what calls my attention is how you use the Url::to() function. Not sure why you use ../. I have fiddled with using more than one modal in a form and the code is similar to what your are doing. I suggest you try changing your Url::to() function as follows:
Url::to('/ticket-timbangan/list')
and
Url::to('/contract/list')
Another suggestion would be to try with
Yii::$app->urlManager->createUrl('/ticket-timbangan/list')
and
Yii::$app->urlManager->createUrl('/contract/list')
Let me know if this helps.
First, many thanks to kalu who has helped me 2 days to solve my problem. Two modals which contains grid need to define different classes to prevent execute previous script.
'value' => Url::to('../ticket-timbangan/list') and 'value' => Url::to('../contract/list'), both has two gridview and same select-row class. This class is root cause of the problem, because it's same class and execute both script.
Thanks Kalu, you save my day.

Yii 2 Editable, how to use editable inside form?

$form = ActiveForm::begin();
..
echo Editable::widget([ //this break outter form, because this generate another form
'name'=>'person_name',
'asPopover' => true,
'value' => 'Kartik Visweswaran',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
ActiveForm::end();
So, I tried,
echo Form::widget([
'model'=>$model,
'form'=>$form,
'columns'=>1,
'attributes'=>[
'title'=>[
'label'=>false,
'type' => Editable::INPUT_TEXT,
'widgetClass' => Editable::className(),
'options' => [
'asPopover' => true,
]
],
]
]);
but, it shows input box all the time, not editable text.
how can I use editable widget inside form? without breaking outter form?
You can try this way:
<?= $form->field($model, 'person_name')->Editable::widget([
'name'=>'person_name',
'asPopover' => true,
'value' => 'value',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
?>
Note : Not tested yet.

Remove line break from CakePHP form submit and link buttons

I am modifying my login form in CakePHP, and want to add Register Button after Login button. However CakePHP creates line break between these two elements:
My login.ctp file:
<?php
/**
* Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* #copyright Copyright 2010 - 2011, Cake Development Corporation (http://cakedc.com)
* #license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
<div class="row-fluid">
<div class="span4"></div>
<div class="span4">
<fieldset>
<?php
echo $this->Form->create($model, array(
'plugin' => 'users', 'controller' => 'users',
'language' => $this->Session->read('Config.language'),
'id' => 'LoginForm', 'class' => 'well'));
?>
<div class="row-fluid">
<?php
if ($_SERVER['HTTP_HOST'] == Configure::read('webakis.touchscreen_host')) {
echo $this->Form->input('name', array(
'label' => __('Name'), 'class' => 'span12'));
echo $this->Form->input('surname', array(
'label' => __('Surname'), 'class' => 'span12'));
} else {
echo $this->Form->input('email', array(
'label' => __('Email or name surname'), 'type' => 'text', 'class' => 'span12'));
}
echo $this->Form->input('password', array(
'label' => __('Password'), 'class' => 'span12'));
// echo '<p>' . $this->Form->checkbox('remember_me') . __( 'Remember Me') . '</p>';
//echo '<p>' . $this->Html->link(__( 'I forgot my password'), array('action' => 'reset_password')) . '</p>';
echo $this->Form->hidden('User.return_to', array(
'value' => $return_to));
// echo $this->Form->end(__( 'Sing in') );
?>
<div class="row-fluid">
<?php
echo $this->Form->submit(__('Sign in'), array('class' => 'btn span6'));
echo $this->Html->link(__('Create an Account'), array('plugin' => 'users', 'controller' => 'users', 'action' => 'add'), array('class' => 'btn span6'));
?>
</div>
<p><?php
if ($_SERVER['HTTP_HOST'] !== Configure::read('webakis.touchscreen_host')) {
echo $this->Html->link(__('Forgot your password?'), array('action' => 'reset_password'));
}
?>
</p>
<div class="btn btn-facebook"><i class="fa fa-facebook"></i>
<?php echo $this->Html->link('Connect with Facebook', $fb_login_url);?>
</div></br></br>
</div><?php echo $this->Form->end(); ?>
</form>
</fieldset>
</div>
<div class="span4"></div>
</div>
I have tried to use Bootstrap "row-fluid" class to put them in one line, but it doesn't work.
It's not a linebreak as in <br>, it's that the button is being wrapped in a block element (div by default).
Either disable it
echo $this->Form->submit(__('Sign in'), array(
'class' => 'btn span6',
'div' => false
));
or use the after option to inject your other button/link into the wrapping element:
$link = $this->Html->link(__('Create an Account'), array(
'plugin' => 'users',
'controller' => 'users',
'action' => 'add'
),
array('class' => 'btn span6'));
echo $this->Form->submit(__('Sign in'), array(
'class' => 'btn span6',
'after' => $link
));
See also http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#options

cakePHP & Boostrap insert html code into form - radio - option

Is it possible to insert custom html code into a options name with Bootstraps formhelper?
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => 'foo'),
'type' => 'radio'
));
?>
I would like it to be
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => '<span class="italic">f</span>oo'),
'type' => 'radio'
));
?>
But when I insert the code it's being stripped from the output.
Im not sure which BoostrapForm helper you are using, but have you considered putting a flag escape as false ?
<?php
echo $this->BootstrapForm->input('where', array(
'options' => array('1' => '<span class="italic">f</span>oo'),
'type' => 'radio',
'escape' => false,
));
?>