commit c49e14c6b7d5b0df0236dd1835fb8a86a21b6688
parent 9adb7e510bb607b0301d552fd479cbdd5d60f014
Author: MoiBaguette <[email protected]>
Date: Sat, 24 Jun 2023 14:03:04 +0200
form_v2
Diffstat:
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/Lollipop/DatabaseObject.php b/Lollipop/DatabaseObject.php
@@ -172,7 +172,7 @@ namespace Lollipop {
public function notNullable(){
//non-auto-increment not-nullable collumn names query
$col_names = [];
- $sql = " SELECT is_nullable
+ $sql = " SELECT column_name, is_nullable
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '{$this->table}'
AND TABLE_SCHEMA = '{$this->schema}'";
@@ -185,9 +185,8 @@ namespace Lollipop {
}
while($tmp = $result->fetch_assoc()){
if($tmp["is_nullable"] == 'NO'){
- if($tmp["extra"] == "auto_increment")
- continue;
- $col_names[] = $tmp["column_name"];
+ if(!$tmp["extra"] == "auto_increment")
+ $col_names[] = $tmp["column_name"];
}
}
return $col_names;
diff --git a/routing/course.php b/routing/course.php
@@ -9,7 +9,7 @@ $course_get = function(&$vars){
$course->load($_POST["search"]);
$data = $course->getData();
}
- $vars["form"] = $templates->form("/course");
+ $vars["form"] = $templates->form_v2("/course");
$vars["search"] = $templates->search_form("/course/search");
$vars["table"] = $templates->crud_table("/course", "" ,"name");
return "views/course.html";
@@ -22,14 +22,19 @@ $course_post = function(&$vars){
$data = [];
if(isset($_POST["form_type"])){
- if($_POST["form_type"] == 'Add')
- $course->add_course();
- elseif($_POST["form_type"] == 'Update'){
- $course->update_course();
+ if($_POST["form_type"] == 'Add'){
+ if($course->add_course()){
+ $vars["response"] = 'succesfully added: ' . $_POST["name"];
+ }
+ } elseif($_POST["form_type"] == 'Update'){
+ if($course->update_course()){
+ $vars["response"] = 'succesfully updated: ' . $_POST["name"];
+ }
}
}
+
- $vars["form"] = $templates->form("/course", $data);
+ $vars["form"] = $templates->form_v2("/course", $data);
$vars["search"] = $templates->search_form("/course");
$vars["table"] = $templates->crud_table("/course", "", "name");
return "views/course.html";
@@ -39,7 +44,7 @@ $course_query = function(&$vars){
global $db;
$course = $db->get(Model\Course::class);
$templates = new controller\templates($db, $course);
- $vars["form"] = $templates->form("/course");
+ $vars["form"] = $templates->form_v2("/course");
$vars["search"] = $templates->search_form("/course/search");
$vars["table"] = $templates->crud_table("/course", $vars["search_query"], "name");
return "views/course.html";
@@ -69,7 +74,7 @@ $course_edit = function(&$vars){
foreach($course->getData() as $key => $col){
$data[$key] = $col;
}
- $vars["form"] = $templates->form("/course", $data);
+ $vars["form"] = $templates->form_v2("/course", $data);
$vars["search"] = $templates->search_form("/course/search");
$vars["table"] = $templates->crud_table("/course", "", "name");
return "views/course.html";
@@ -81,7 +86,7 @@ $course_delete = function(&$vars){
$templates = new controller\templates($db, $course);
$course->load($vars["primary_key"]);
$course->delete();
- $vars["form"] = $templates->form("/course");
+ $vars["form"] = $templates->form_v2("/course");
$vars["search"] = $templates->search_form("/course");
$vars["table"] = $templates->crud_table("/course" ,"", "name");
return "views/course.html";
diff --git a/views/course.html b/views/course.html
@@ -13,6 +13,7 @@
<h1>Add Course</h1>
<a href="/course">New</a>
{{$form}}
+ {{$response}}
</div>
</div>
<div class = "courses">