Skip to content

Commit f20a54a

Browse files
committed
Add Data Input Validation
1 parent 1b8de3e commit f20a54a

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

Models/Classes.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ namespace CMS.Models
66
public class Classes
77
{
88
[Key]
9+
910
public int ID { get; set; }
10-
[Required]
11+
12+
[Required(ErrorMessage = "Period is required.")]
13+
[Range(1, 10, ErrorMessage = "Period must be between 1 and 10.")]
1114
public int period { get; set; }
12-
[Required]
15+
16+
[Required(ErrorMessage = "Class name is required.")]
17+
[StringLength(100, ErrorMessage = "Class name can't be longer than 100 characters.")]
1318
public string className { get; set; }
1419
}
1520
}

Views/Record/AddClass.cshtml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@model Classes
22

33
<div class="min-h-screen text-center">
4-
<p class="dark:text-white font-bold tect-2xl md:text-5xl justify-center items-center pb-10">Add Classes</p>
4+
<p class="dark:text-white font-bold tect-2xl md:text-5xl justify-center items-center pb-10">Add a Class</p>
55

6-
<form method="post">
6+
<form method="post" asp-controller="Record" asp-action="AddClass">
77
<table class="min-w-full bg-transparent shadow-md rounded-lg text-center">
88
<thead>
99
<tr>
@@ -14,27 +14,29 @@
1414
<tbody>
1515
<tr class="border-t">
1616
<td class="py-2 px-4">
17-
<input asp-for="period" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter period" />
17+
<input asp-for="period" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 dark:text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter period" />
18+
<span asp-validation-for="period" class="text-danger"></span>
1819
</td>
1920
<td class="py-2 px-4">
20-
<input asp-for="className" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter name" />
21+
<input asp-for="className" type="text" class="form-control w-full bg-transparent rounded px-2 py-1 dark:text-white placeholder-white::placeholder text-center outline-none" placeholder="Enter name" />
22+
<span asp-validation-for="className" class="text-danger"></span>
2123
</td>
2224
</tr>
2325
</tbody>
2426
</table>
2527

2628
<div class="flex items-center justify-center mt-2 f">
2729
<div class="text-center mt-6 inline-flex">
28-
<button type="submit" class="text-white border border-white bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
29-
<i class="bi bi-plus-circle mr-2"> </i> Add to Timetable
30+
<button type="submit" class="dark:text-white border dark:border-white bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
31+
Add to Timetable
3032
</button>
3133
</div>
3234

3335
<div class="w-10"> </div>
3436

3537
<div class="text-center mt-6 inline-flex">
3638
<a asp-controller="Record" asp-action="TimeTable" class="text-gray-400 border border-gray-400 bg-transparent font-semibold hover:bg-gray-500 hover:text-gray-800 py-2 px-4 rounded items-center justify-center transition duration-100 ease-in-out">
37-
<i class="bi bi-plus-circle mr-2"> </i> Back to Timetable
39+
Back to Timetable
3840
</a>
3941
</div>
4042
</div>

wwwroot/images/trash-delete.svg

Lines changed: 4 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)