-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcourse.php
86 lines (74 loc) · 3.2 KB
/
course.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require_once 'core/init.php';
$isError = '';
if (Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validate->check($_POST, array(
'course_name' => array('required' => true),
'course_details' => array('required' => true)
));
if ($validate->passed()) {
$course = new Course();
try {
$course->create(['course_name' => Input::get('course_name'),'course_details' => Input::get('course_details')]);
header('Location: course_list.php');
} catch(Exception $e) {
$isError = $e->getMessage();
//echo $e->getTraceAsString(), '<br>';
}
}
}
}
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css">
<title>Student Courses</title>
</head>
<body class="bg-light">
<div class="container">
<?php if(isset($validate) && $validate->errors()){
foreach ($validate->errors() as $error) { ?>
<div class="alert alert-success" role="alert">
<?php echo $error . "<br>";?>
</div>
<?php }}?>
<?php if(isset($isError) && $isError!=''){ ?>
<div class="alert alert-danger" role="alert">
<?php echo $isError . "<br>";?>
</div>
<?php }?>
<div class="row py-5">
<div class="col-md-8 order-md-1">
<form action="" method="post">
<h1>Add New Course</h4>
<div class="mb-3">
<label for="username">Course Name</label>
<div class="input-group">
<input type="text" class="form-control" id="course_name" name="course_name" placeholder="Course Name" required="">
</div>
</div>
<div class="mb-3">
<label for="username">Course Details</label>
<div class="input-group">
<textarea class="form-control" id="course_details" name="course_details" rows="3" placeholder="Course Details"></textarea>
</div>
</div>
<input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
<button class="btn btn-primary" type="submit">Submit</button>
<?php include('actions_view.php');?>
</form>
</div>
</div>
</div>
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
</body>
</html>