

<?= $this->element('page_top', array('title' => __('Add'), 'permissions' => $user_permission)); ?>

<div class="box box-primary">
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-md-12">
                <?= $this->Form->create(null, ['id' => 'session_form', 'class' => 'input-form-section']); ?>

                <div id="basic_info_div">

                    <div class="col-md-9 col-sm-9 col-xs-9 text-left">

                        <div class="form-group row <?php if (isset($errors['name'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Session Name</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('name', ['label' => false, ['class' => 'required'], 'placeholder' => 'Session Title', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['name']['_empty'])) {
                                                            echo $errors['name']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row <?php if(isset($errors['start_date'])){ echo 'has-error';} ?>">
                            <label class="control-label col-lg-3 required">Start Date</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('start_date', ['label' => false,'type'=>'text', ['class' => 'required' ], 'value'=> "",  'placeholder' => 'Session Start Date(DD-MM-YYYY)', 'class' => 'form-control', 'required' => false,'autocomplete' => 'off']); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['start_date']['_empty'])) {
                                                            echo $errors['start_date']['_empty'];
                                                        }
                                                        ?>
                                    </span>

                            </div>
                        </div>
                        <div class="form-group row <?php if (isset($errors['duration_month'])) {
                            echo 'has-error';
                        } ?>">
                            <label class="control-label col-lg-3 required">Duration</label>
                            <div class="col-lg-9">
                                <?php echo $this->Form->input('duration_month', ['label' => false, ['class' => 'required'], 'placeholder' => 'Session Duration Month', 'class' => 'form-control', 'required' => false]); ?>
                                <span class="help-block text-center">
                                                        <?php
                                                        if (isset($errors['duration_month']['_empty'])) {
                                                            echo $errors['duration_month']['_empty'];
                                                        }
                                                        ?>
                                        </span>
                            </div>
                        </div>
                        <div class="form-group row ">
                            <label class="control-label col-lg-3"></label>
                            <div class="col-lg-9">
                                <?= $this->Form->button(__('Submit'), ['class' => 'btn btn-success tab3Save pull-left btn-grid btn-flat', 'id' => 'submit']) ?>
                                <a href="<?php echo $this->Url->build('/session'); ?>"
                                   class="btn btn-default tab3Save pull-left btn-grid btn-flat btn-orange-color"
                                   id="default-btn">
                                    <?php echo __('Back'); ?>
                                </a>
                            </div>
                        </div>

                    </div>

                    <!-- /.form-group -->
                </div>
                <?= $this->Form->end() ?>
                <!-- /.form-group -->


            </div>
            <!-- /.row -->
        </div>
        <!-- /.box-body -->

    </div>
</div>

<script type="application/javascript">

    $(document).ready(function () {
        $('input[name="start_date"]').datepicker({autoclose: true, todayHighlight: true, format: 'dd-mm-yyyy',orientation: 'bottom auto'});
    });

    $('#session_form').validate({
        rules: {
            'name': 'required',
            'start_date': {'required': true,},
            'duration_month': {'required': true, 'digits': true}

        },
        messages: {
            'name': {required: "Please enter session title"},
            'start_date': {required: "Please enter session start date(YYYY-MM-DD)"},
            'duration_month': {
                required: "Please enter session duration",
                digits: "Please enter number of month"
            }
        },
        highlight: function (element) {
            $(element).parent().addClass("has-error");
        },
        submitHandler: function (form) {
            form.submit();
        }
    });

</script>

