<div class="title">新增課程次分類</div>
<ul class="table-toolbar"style="text-align: left;">
    <li><a class="toolbar-element btn btn-default btn-create" href="/course_subcategory" ><i style="margin-right: 8px;"><span class="iconify" data-icon="typcn-arrow-back" data-inline="false"></span></i>返回</a></li>
</ul>
<div class="form-container">
    <form id="frmphp" class="form-horizontal" role="form" method="post" action="/course_subcategory/insert">
        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="course_category_id">課程主分類</label></div>
            <div class="col-sm-9 mas-box">
                <select id="course_category_id" class="select mas-select"name="course_category_id" >
                    <option value="" selected="selected">--- 請選擇課程主分類 ---</option>
                    <?php
                    foreach ($course_category as $category) {
                        echo sprintf('<option value="%s">%s</option>', $category['id'], $category['name']);
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="name">課程次分類</label></div>
            <div class="col-sm-9 mas-box"><input id=name type="text" class="form-control mas-input" name="name" placeholder="輸入課程次分類名稱" /></div>
        </div>
        <div class="form-group mas-col">
            <div class="col-sm-3 text-center mas-title"><label for="remark">備註</label></div>
            <div class="col-sm-9 mas-box"><textarea id="remark"  class="form-control mas-textarea" rows="3" name="remark" ></textarea></div>
        </div>
        <div class="form-footer">
            <a class="btn btn-footer reset" href="javascript:window.location.reload(true)">重設</a>
            <button class="btn btn-footer submit" id="btnSubmit" type="button">提交</button>      
        </div>
    </form>
</div>
<script>
    $(document).ready(function () {
        var li = $('#sidebar-menu li').filter(function(i){
            return $(this).find('.menu-dropdown').find('.menu-text').text()===' 課程';
        });
        li.addClass('active open');
    });
    
    function validform() {
        var msg = '';
        if($('#course_category_id').val()===''){
            msg+="請選擇課程主分類\n";
        }
        if ($('#name').val() === '') {
            msg += "請輸入課程次分類名稱\n";
        }
        if (msg !== '') {
            alert(msg);
        }
        return msg==='';
    }

   $(document).on('click','#btnSubmit', function () {
        if (validform()) {
            $('#frmphp').submit();
        }
    });
</script>