CakePHP 3 - Best Practice and Cookbook

Next: CakePHP 3 and REST UP: TOC

The example below show a complex horizontal form using dates, times and pop lists.


Form->create('Availabilities', [
   'url' => '/padm/availabilities/add/' . $this->viewVars['object']['id'],
   'class' => 'form-horizontal'
]);

$this->Form->templates([
    'inputContainer' => '
{{content}}
' ]); ?>

Here you can publish when your item in bookable. This is usually a full day or half day. You can add as many as you like as long they do not overlap.

Form->input('price',[ 'label' => ['class' => 'col-sm-2 control-label', 'text' => __('Price')] ]); echo '
'; echo $this->Form->label('Availabilities.starttime','Start', array('class' => 'col-sm-2 control-label')); echo $this->Form->datetime('starttime',[ 'dateFormat'=>'YMD', 'minYear'=> date('Y') , 'maxYear' => date('Y')+2, 'interval' => 30, 'value' => '07:00:00', 'timeFormat' => 24, 'empty' => false ]); echo '
'; echo '
'; echo $this->Form->label('Availabilities.starttime','Start', ['class' => 'col-sm-2 control-label']); echo $this->Form->datetime('endtime', [ 'dateFormat'=>'YMD', 'label' => ['class' => 'col-sm-2 control-label', 'text' => __('Endtime') . ' (' . __('For non-season leave this field blank') . ')'], 'minYear'=> date('Y') , 'maxYear' => date('Y')+3, 'value' => '22:00:00', 'interval' => 30, 'timeFormat' => 24, 'empty' => false ]); echo '
'; echo $this->Form->input('remarks',[ 'label' => ['class' => 'col-sm-2 control-label', 'text' => __('Remarks')] ]); echo '
'; echo $this->Form->label(null,'Repeat until', ['class' => 'col-sm-2 control-label']); echo $this->Form->date('repeatend',[ 'dateFormat'=>'YMD', 'minYear'=> date('Y') , 'maxYear' => date('Y')+3, 'empty' => false ]); echo '
'; echo $this->Form->input('repeattype', [ 'label' => ['text' => __('Repeat Type'),'class' => 'col-sm-2 control-label'], 'type' => 'select', 'multiple' => false, 'options' => ['d' => __('daily'),'w' => __('weekly')], 'empty' => false ]); echo $this->Form->hidden('obj_id',['value' => $this->viewVars['object']['id']]); echo $this->Form->submit(__('Save'),['class' => 'btn btn-primary']); echo $this->Form->end(); ?>

The above code will produce this browser form:

Horizontal Form with CakePHP3 and Bootstrap3 Next: CakePHP 3 and REST UP: TOC