Formulare hinzugefügt

This commit is contained in:
R40fendt
2025-12-24 00:27:19 +01:00
parent 9e18989b42
commit b6e9462d68
5 changed files with 99 additions and 1 deletions

29
formulare/get_fields.php Executable file
View File

@@ -0,0 +1,29 @@
<?php
header("Access-Control-Allow-Origin: *");
if(!isset($_GET["formular"])) die("GET formular fehlt");
$formular=$_GET["formular"];
include("../../mysqlverbinden.php");
$data=[];
foreach(mysqli_execute_query($db_id,"SELECT `id`,`formular`, `name`, `displayname`, `value`, `displayvalue`, `placeholder`, `type`, `title`, `required`, `maxlength`, `min`,`max`, `checked` FROM `formulare-fields` WHERE `formular`=? ORDER BY `id` ASC;",[$formular]) as $row){
$data[]=[
"id"=>$row["id"],
"formular"=>$row["formular"],
"name"=>$row["name"],
"displayname"=>$row["displayname"],
"value"=>$row["value"],
"displayvalue"=>$row["displayvalue"],
"placeholder"=>$row["placeholder"],
"type"=>$row["type"],
"title"=>$row["title"],
"required"=>$row["required"],
"maxlength"=>$row["maxlength"],
"min"=>$row["min"],
"max"=>$row["max"],
"checked"=>$row["checked"],
];
}
echo json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);

17
formulare/get_formulare.php Executable file
View File

@@ -0,0 +1,17 @@
<?php
header("Access-Control-Allow-Origin: *");
include("../../mysqlverbinden.php");
$data=[];
foreach(mysqli_execute_query($db_id,"SELECT `id`,`name`,`minitext`,`public`,`multiple` FROM formulare;",[]) as $row){
$data[]=[
"id"=>$row["id"],
"name"=>$row["name"],
"minitext"=>$row["minitext"],
"public"=>$row["public"],
"multiple"=>$row["multiple"],
];
}
echo json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);

32
formulare/get_results.php Executable file
View File

@@ -0,0 +1,32 @@
<?php
header("Access-Control-Allow-Origin: *");
include("../../mysqlverbinden.php");
if(!isset($_GET["id"])) die("GET id fehlt");
$formularid=$_GET["id"];
function get_type_by_name($name){
global $db_id;
return mysqli_fetch_assoc(mysqli_execute_query($db_id,"SELECT `type` FROM `formulare-fields` WHERE `name`=?;",[$name]))["type"];
}
$data=[];
foreach(mysqli_execute_query($db_id,"SELECT `id`,`timestamp` FROM `formulare-ergebnisse`") as $ergebnis){
foreach(mysqli_execute_query($db_id,"SELECT `id`,`name`,`value` FROM `formulare-ergebnis` WHERE `ergebnisid`=?;",[$ergebnis["id"]]) as $row){
$type=get_type_by_name($row["name"]);
if(str_ends_with($row["name"],'[]')){
$row["name"]=substr($row["name"], 0, -2);
$row["value"]=json_decode($row["value"]);
}
$ergebnis["data"][]=[
"id"=>$row["id"],
"name"=>$row["name"],
"value"=>$row["value"],
"type"=>$type
];
}
$data[]=$ergebnis;
}
echo json_encode($data,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);

20
formulare/submit.php Executable file
View File

@@ -0,0 +1,20 @@
<?php
header("Access-Control-Allow-Origin: *");
include("../../mysqlverbinden.php");
if(!isset($_POST["internalformid"])) die("POST internalformid fehlt");
$formid=$_POST["internalformid"];
print_r($_POST);
mysqli_execute_query($db_id,"INSERT INTO `formulare-ergebnisse` (`formular`) VALUES (?);",[$formid]);
$id = mysqli_insert_id($db_id);
echo $id;
foreach($_POST as $key => $value){
if($key=="internalformid") continue;
if(is_array($value)){
$value=json_encode($value,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
$key.="[]";
}
mysqli_execute_query($db_id,"INSERT INTO `formulare-ergebnis` (`name`, `value`,`ergebnisid`) VALUES (?,?,?);",[$key,$value,$id]);
}

View File

@@ -1 +1 @@
3 5