bootstrap selectpicker: Make a select drop down required - bootstrap-select

I am using bootstrap selectpicker and i want to make a dropdown required. What is the proper way to make a bootstrap selectpicker select required.
(i didn't want's to use any other jquery plugin).
{!! Form::select('from', [], null, ['class' => 'selectpicker form-control', 'data-live-search' => '1', 'data-size' => '6', 'title' => 'Select a partner',]) !!}
I am using that selectpicker into laravel form collective.

use html5's required
<select class="form-control selectpicker" name="txt_kode_supp" required>
for laravel collective:
insert array('required' => 'required') into your form collective 3rd parameter


CakePHP 3.4 use setTemplates() multiple times

I'm trying to use setTemplates() multiple times in a view, but it doesn't work as expected.
I have two templates which I want to set when I need them.
$bootstrapTemplate = [
'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}</div>',
$bootstrapTemplateInputGroup = [
'inputContainer' => '<div class="form-group {{type}}{{required}}">{{content}}</div>',
'input' => '<div class="input-group"><div class="input-group-addon">€</div><input type="{{type}}" name="{{name}}"{{attrs}}/></div>'
I start to set the templates like this
$this->Form->control('title', ['class' => 'form-control', 'label' => __('Titel')]);
// OUTPUT - correct
// <div class="form-group text required"><label for="title">Titel</label><input type="text" name="title" class="form-control" required="required" maxlength="255" id="title"></div>
echo $this->Form->control('price', ['class' => 'form-control', 'id' => 'price_eur', 'label' => __('Preis EUR')]).'</div>';
// OUTPUT - correct
<div class="form-group number required"><label for="price_eur">Preis EUR</label><div class="input-group"><div class="input-group-addon">€</div><input type="number" name="price" class="form-control" id="price_eur" required="required" step="any"></div></div>
Now I want to switch back to $bootstrapTemplate which doesn't seem to work. Instead the $bootstrapTemplateInputGroup is used
echo $this->Form->control('user_zip', ['class' => 'form-control', 'id' => 'user_zip', 'label' => __('PLZ')])
// OUTPUT - wrong
<div class="form-group text"><label for="user_zip">PLZ</label><div class="input-group"><div class="input-group-addon">€</div><input type="text" name="user_zip" class="form-control" id="user_zip"></div></div>
My expected output is the template of $bootstrapTemplate like:
<div class="form-group text required"><label for="user_zip">PLZ</label><input type="text" name="user_zip" class="form-control" required="required" maxlength="255" id="user_zip"></div>
What am I doing wrong here?
FormHelper::setTemplates() doesn't overwrite the complete existing set of templates, it merges it with the given templates, ie the input template set with the second call, will remain changed.
You either have to push() to (store) and pop() from (restore) the template stack using the underlying templater to avoid that:
or use the FormHelper::create() method's templates option to apply the templates to the specific FormHelper::control() call(s) only:
echo $this->Form->control('title', ['templates' => $bootstrapTemplate, /*...*/]);
echo $this->Form->control('price', ['templates' => $bootstrapTemplateInputGroup, /*...*/]);
echo $this->Form->control('user_zip', ['templates' => $bootstrapTemplate, /*...*/]);
See also
Cookbook > Views > Helper > Form > Options for Control
API > \Cake\View\StringTemplate

How to convert below code in CakePHP 3?

<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Title</label>
<div class="col-lg-10">
<input type="text" style="width: 45%;" class="form-control" id="titleId" name="title" placeholder="Title">
I have this type of code in my add.ctp file and I don't know how to convert it into like
<? echo $this->Html->input('title',['class'=>'']);
You have to use Form helper instead of CakePHP Html helper. Form helper helps you to create form field as well as help to validate the form. But Html helper helps you to create Html like Html for image displaying. Here we go
$this->Form->input('title', [
'label' => [
'text' => 'Title',
'class' => 'col-lg-2'
'style' => [
'width: 45%;'
I would like to advise you to go to this link, have a deeper look on the docs :)
Here is the Form helper of CakePHP 3
Here is the Html helper of CakePHP 3

Multiple file upload in custom form with managed_file

I'm building a custom settings form in Drupal 7, with an image upload field. This image field should allow multiple uploads.
After some research I found out you can do this with managed_file and '#attributes' => array('multiple' => 'multiple'). However this doesn't seem to do anything.
This is the code I currently have:
$form['frontpage_banner_images'] = array(
'#type' => 'managed_file',
'#title' => t('Frontpage Images'),
'#name' => 'files[]',
'#attributes' => array(
'multiple' => 'multiple',
'class' => 'testclass',
'#upload_location' => 'public://homepage-banners/',
'#default_value' => variable_get('frontpage_banner_images'),
With this as result:
<div class="form-item form-type-managed-file form-item-files-">
<label for="edit-frontpage-banner-images-upload">Frontpage Images</label>
<div id="edit-frontpage-banner-images-upload" class="testclass form-managed-file">
<input type="file" id="edit-frontpage-banner-images-upload" name="files[frontpage_banner_images]" size="22" class="form-file">
<input type="submit" id="edit-frontpage-banner-images-upload-button" name="frontpage_banner_images_upload_button" value="Upload" class="form-submit ajax-processed">
<input type="hidden" name="frontpage_banner_images[fid]" value="0">
As you can see, the testclass from my #attributes is being applied on the wrapping div and not on the file input. So the multiple attribute isn't doing anything.
This is what I'm trying to achieve (Photoshopped):
Any help on how to achieve this is appreciated.
The multiple option does not seem to be supported. Then again you are using it under the #attributes. This would cause IMO the html element to have an atttribute multiple, but I don't see anything in /modules/file/file.js to pick up on that, so that's presumably why it's not doing anything.
You're probably better off using plupload, as suggested here.

Cakephp 3 - select not submitted if no selection is made

I have a form ( generated using the form helper ) with this select input
<div class="input select">
<label for="pilot-ratings">Pilot Ratings</label>
<select name="pilot_ratings" class="listbox" size="5" id="pilot-ratings">
<option value="1">Habilitación de Vuelo Nocturno Local</option>
<option value="3">Habilitación Cat. II / Cat. III</option>
<option value="5">Habilitación de Remolque de Planeador</option>
Only when an option is selected, that option is added to $this->request->data['pilot_ratings'].
Is there any way to force submitting all of the options of the select input every time no matter an option is selected or not ?
How are you moving options between the select boxes?
to automatically submit an option you need to add selected="selected" attribute to the <option> element. To submit many options in a select box in the form you need to add multiple to the <select> element
if you want to automatically submit all options in the list on page load it would need to look like this
<select name="pilot_ratings" class="listbox" size="5" id="pilot-ratings" multiple>
<option value="1" selected="selected">Habilitación de Vuelo Nocturno Local</option>
<option value="3" selected="selected">Habilitación Cat. II / Cat. III</option>
<option value="5" selected="selected">Habilitación de Remolque de Planeador</option>
this can be acheived using the cakephp Form helper like:
<?= $this->Form->input('pilot_ratings',[
'type' => 'select',
'class' => 'listbox',
'size' => 5,
'id' => 'pilot_ratings',
'multiple' => 'multiple',
'options' => [
['name' => 'Habilitación de Vuelo Nocturno Local', 'value' => '1', 'selected' => 'selected'],
['name' => 'Habilitación Cat. II / Cat. III', 'value' => '2', 'selected' => 'selected'],
['name' => 'Habilitación de Remolque de Planeador', 'value' => '5', 'selected' => 'selected']
]); ?>
Havent tested the syntax of the form helper code but it is the right idea.
One thingI just thought about is how you read the data after the form has been submitted. The data will still be submitted like:
By default I think (havnt actually tested this) $this->request->data['pilot_ratings']; will only hold one of these values, either the 1st one-or the last one as it keeps overwritting itself.
If this that is the case you may need to change the form method to get
and then extract all the values from the query string which you can get from:

How to add attribute to an input in Cakephp

I'm developing an app in cakePHP and I'd like to use Foundation Tooltips into it.
I need to add data-tooltip to the input in order to make it work, but I don't know how to do it with the cakePHP form helper.
Right now I'm using:
<?php echo $this->Form->input('title', (array( 'label' => __('title'),
'class' => 'has-tip',
'title' => __('Tooltip for initiative title'),
And is returning this:
<input name="data[Initiative][title]" class="has-tip" title="Tooltip for initiative title" maxlength="255" type="text" id="InitiativeTitle" required="required">
When I need this:
<input data-tooltip name="data[Initiative][title]" class="has-tip" title=...>
I've tried adding 'data-tooltip'to the input array with no luck, but I'm sure it has to be an easy way of doing it.
Thanks in advance and sorry for my English.
<?php echo $this->Form->input('title', array( 'label' => __('title'),
'class' => 'has-tip',
'title' => __('Tooltip for initiative title'),