JezK
Edit File: add_subject.php
<?php session_start(); include("session_check.php"); include "adm_operations.php"; $operations=new adm_operations(); include('school_timeout.php'); if(isset($_POST['add_sub'])) { $acdid=$_SESSION['child']['choosen_academic_id']; $add=$operations->addnewsubjectToSchool($_SESSION['child']['auth_id'],$_SESSION['child']['log_school_id'],$_POST['class_cat'],$_POST['subject_name'],$acdid); if($add=='success') { $_SESSION['child']['calcat']=$_POST['class_cat']; echo "<script>location.replace('subject_management.php?calcat=".$_POST['class_cat']."')</script>"; //header("subject_management.php?calcat=".$_POST['class_cat']); } else if($add=='exist') echo "<script>alert('Subject already exists in the same Category')</script>"; else echo "<script>alert('Subject adding failed')</script>"; } include("header.php"); ?> <script> function validatefields() { var clscat=document.getElementById('class_cat').value; var sub_name=document.getElementById('subject_name').value; var reg=/^[A-Za-z\d\-_\s]+$/i; $('#err_class_cat').text(''); $('#err_subject_name').text(''); if(clscat==0) { $('#err_class_cat').text("Please select Class Category"); document.getElementById('class_cat').focus(); return false; } else if(sub_name=='') { $('#err_subject_name').text("Please enter Subject Name"); document.getElementById('subject_name').focus(); return false; } else if(!reg.test(sub_name)) { $('#err_subject_name').text("Please enter a valid Subject Name"); document.getElementById('subject_name').focus(); return false; } } function returntoprev() { window.location.href='subject_management.php'; } </script> <body style=" overflow-x: hidden;"> <div class="row" style="margin-top:30px;"> <div class="col-md-3 text-center" style="font:Arial, Helvetica, sans-serif;font-style:normal;font-size:14px; color:#000000; font-size:1.4em;margin-left:-35px;"> <i class=" glyphicon glyphicon-plus " title ="Add School" style="font-size: 16px;"></i> Add Subject </div> </div> <form class="form-horizontal" method="post"> <div class="box-body" style="background-color:#fff; padding: 10px; font-family:Arial, Helvetica, sans-serif; font-size:13px; margin-top:20px;"> <div class="clear"> <div class="form-group col-md-6" style="margin-bottom:1.0%;"> <div class="col-md-4 text-right"> <b style="color:#666666;">Choose Category</b> <span style="color:#FF0000; margin-left:-3px;">*</span> </div> <div class="col-md-7"> <select class="form-control" id="class_cat" style="height:29px; font-size:12px;" name="class_cat" tabindex="1" > <?php $arr=array("Select Category","Junior","Primary","Higher Secondary","Senior Secondary"); foreach($arr as $key=>$val) if($key==$_POST['class_cat']) echo "<option value='".$key."' selected>".$val."</option>"; else echo "<option value='".$key."'>".$val."</option>"; ?> </select> <!-- if there is an error--> <div class="col-md-10" id="err_class_cat" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> </div> <div class="class"> <div class="form-group col-md-6" style="margin-bottom:1.0%; clear:both;"> <div class="col-md-4 text-right"><b style="color:#666666;">Subject Name </b><span style="color:#FF0000; margin-left:-2px;">*</span> </div> <div class="col-md-7"> <input type="text" class="form-control" id="subject_name" name="subject_name" style="height:29px;font-size:13px;" tabindex="2" value="<?php echo $_POST['subject_name'];?>" maxlength="50"> <!-- if there is an error--> <div class="col-md-10" id="err_subject_name" style="color:#990000;margin-left:-15px;"></div> <!--- end error--> </div> </div> <div class="form-group"> <div class="col-md-7" align="center"> <button type="submit" class="btn btn-default custom-button-width .navbar-right btnclr" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" name="add_sub" onclick="return validatefields();" tabindex="3">Add</button> <button type="button" class="btn btn-default custom-button-width .navbar-right btnclr" style="font-family:Arial, Helvetica, sans-serif;font-style:normal;font-size:13px; margin:10px;" onclick="returntoprev()" tabindex="4">Cancel</button> </div> </div> </div> </form> </div> </body> </html>