Updated create_category.php to use the Post-Redirect-Get pattern.

This commit is contained in:
2020-04-07 22:11:55 -05:00
parent aa2cbba34d
commit 28223a67ad
2 changed files with 39 additions and 22 deletions
+27 -9
View File
@@ -1,14 +1,26 @@
<html>
<head>
<?php
//Use require for all DB interaction code
//https://stackoverflow.com/questions/2418473/difference-between-require-include-require-once-and-include-once
require "db/item_info.php";
$base_attributes = get_item_base_attributes();
$new = get_item_base_attributes();
?>
<html>
<head>
if($_POST){
$posted = filter_input_array(INPUT_POST);
foreach($posted as $post){
var_dump($post);
}
unset($_POST);
//Post-Redirect-Get pattern
//https://stackoverflow.com/questions/4142809/simple-post-redirect-get-code-example
header("Location: " . $_SERVER['REQUEST_URI']);
exit();
}
?>
<title>Create New Category</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
<?php
@@ -45,10 +57,9 @@
<fieldset id="field_set">
<legend>This is a legend</legend>
<div id="form_row">
<label for="category_details">Category Detail:</label><input type="text" id="category_detail" name="category_detail">
<label for="category_details">Category Detail:</label><input type="text" id="category_detail" name="category_detail[]">
<label for="category_details_select">Data Type:</label>
<select name="category_details_select">
<select name="category_details_select[]">
<?php
foreach(get_supported_data_types() as $key => $value){
echo "<option value='$key'>$value</option>";
@@ -78,10 +89,17 @@
function insertNewRow(){
let newRow = document.createElement('div');
let form = document.getElementById('field_set');
let target = document.getElementById('add_row');
let count = document.querySelectorAll('#field_set #category_detail');
let clone = document.getElementById('form_row').cloneNode(true);
var array = Array.from(document.getElementById('form_row').children);
array.forEach(child => console.log(child));
//setAttribute("name", "details[$count]");
newRow.appendChild(document.getElementById('form_row').cloneNode(true));
form.insertBefore(newRow, target)
form.insertBefore(newRow, document.getElementById('add_row'))
}
</script>
-1
View File
@@ -10,7 +10,6 @@ body {
input {
background-color: #aea8a5;
border: 0px;
}
button {