【发布时间】:2021-10-15 02:52:36
【问题描述】:
使用按钮提交时不发送任何输入。 据我所知,提交块(isset ...)应该没问题。但是变量 name、kuerzel 和 website 中没有任何内容。
有人可以帮我吗?
body {
color: #566787;
background: #f5f5f5;
font-family: 'Varela Round', sans-serif;
font-size: 13px;
zoom: 105%
}
.table-responsive {
margin: 30px 0;
}
.table-wrapper {
background: #fff;
padding: 20px 25px;
border-radius: 3px;
box-shadow: 0 1px 1px rgba(0, 0, 0, .05);
}
.table-title {
padding-bottom: 15px;
background: #ee8813;
color: #fff;
padding: 16px 30px;
margin: -20px -25px 10px;
border-radius: 3px 3px 0 0;
}
.table-title h2 {
margin: 5px 0 0;
font-size: 24px;
}
.table-title .btn-group {
float: right;
}
.table-title .btn {
color: #fff;
float: right;
font-size: 13px;
border: none;
min-width: 50px;
border-radius: 2px;
border: none;
outline: none !important;
margin-left: 10px;
}
.table-title .btn i {
float: left;
font-size: 21px;
margin-right: 5px;
}
.table-title .btn span {
float: left;
margin-top: 2px;
}
table.table tr th, table.table tr td {
border-color: #e9e9e9;
padding: 12px 15px;
vertical-align: middle;
}
table.table tr th:first-child {
width: 60px;
}
table.table tr th:last-child {
width: 100px;
}
table.table-striped tbody tr:nth-of-type(odd) {
background-color: #fcfcfc;
}
table.table-striped.table-hover tbody tr:hover {
background: #f5f5f5;
}
table.table td:last-child i {
opacity: 0.9;
font-size: 22px;
margin: 0 20px;
}
table.table td a {
font-weight: bold;
color: #566787;
display: inline-block;
text-decoration: none;
outline: none !important;
}
table.table td a:hover {
color: #2196F3;
}
table.table td a.delete {
color: #F44336;
float: right;
}
table.table td i {
font-size: 19px;
}
table.table .avatar {
border-radius: 50%;
vertical-align: middle;
margin-right: 10px;
}
.pagination {
float: right;
margin: 0 0 5px;
}
/* Modal styles */
.modal .modal-dialog {
max-width: 400px;
}
.modal .modal-header, .modal .modal-body, .modal .modal-footer {
padding: 20px 30px;
}
.modal .modal-content {
border-radius: 3px;
}
.modal .modal-footer {
background: #ecf0f1;
border-radius: 0 0 3px 3px;
}
.modal .modal-title {
display: inline-block;
}
.modal .form-control {
border-radius: 2px;
box-shadow: none;
border-color: #dddddd;
}
.modal textarea.form-control {
resize: vertical;
}
.modal .btn {
border-radius: 2px;
min-width: 100px;
}
.modal form label {
font-weight: normal;
}
.btn-add {
background-color: #676767;
}
.btn-add:hover {
background-color: #808080;
transition: 0.2s;
}
td{
width: 25%;
}
.credits{
text-align: center;
margin: 0;
}
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php print(gethostname()); ?> - Websites</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="../../css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
// Activate tooltip
$('[data-toggle="tooltip"]').tooltip();
});
// Delete row on delete button click
$(document).on("click", ".delete", function() {
$(this).parents("tr").remove();
});
</script>
</head>
<!-- Delete Icon -->
<?php $delBtn = "<td><a href='' class='delete' title='Delete' data-toggle='tooltip'><i class='material-icons'></i></a></td>"; ?>
<!-- Add-Function -->
<?php
$name = $kuerzel = $website = '';
if (isset($_POST['submit'])) {
$websiteList = array(
array("$name", "$kuerzel", "$website")
);
$websiteFileTable = fopen('../textFiles/websites.csv', "a");
foreach ($websiteList as $fields) {
fputcsv($websiteFileTable, $fields);
}
fclose($websiteFileTable);
//websites
$websiteFile = fopen('../textFiles/websites.txt', 'a');
$websiteContent = "$website\n";
fwrite($websiteFile, $websiteContent);
fclose($websiteFile);
//redirect
header('Location: test.php');
};
?>
<body>
<div class="container">
<div class="table-responsive">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-xs-6">
<h2>Raspberry Pi | <b><?php print(gethostname()); ?></b></h2>
</div>
<div class="col-xs-6">
<a href="#addWebsiteModal" class="btn btn-add" data-toggle="modal"><i class="material-icons"></i> <span>Website hinzufügen</span></a>
</div>
</div>
</div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Vor-/Nachname</th>
<th>Kürzel</th>
<th>Website</th>
<th></th>
</tr>
</thead>
<?php
$f = fopen("../textFiles/websites.csv", "r");
$flag = true; //Skip first line
while (($line = fgetcsv($f, 1000, ',')) !== false) {
if ($flag) {
$flag = false;
continue;
}
?>
<tbody>
<?php
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "$delBtn";
echo "</tr>\n";
}
fclose($f);
?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Modal HTML -->
<div id="addWebsiteModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="test.php">
<div class="modal-header">
<h4 class="modal-title">Website hinzufügen</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Vor-/Nachname</label>
<input type="text" name="name" value="<?php echo htmlspecialchars($name) ?>" class="form-control" required>
</div>
<div class="form-group">
<label>Kürzel</label>
<input type="text" name="kuerzel" value="<?php echo htmlspecialchars($kuerzel) ?>" class="form-control" required>
</div>
<div class="form-group">
<label>Website</label>
<input type="url" name="website" value="<?php echo htmlspecialchars($website) ?>" class="form-control" required>
</div>
</div>
<div class="modal-footer">
<input type="button" name="cancel" class="btn btn-default" data-dismiss="modal" value="abbrechen">
<input type="submit" name="submit" class="btn btn-success" value="Hinzufügen">
</div>
</form>
</div>
</div>
</div>
</body>
</html>
不知道该写什么了……
Lorem ipsum dolor sit amet,consetetur sadipscing elitr,sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,sed diam voluptua。在 vero eos et accusam et justo duo dolores et ea rebum。 Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet。 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua。在 vero eos et accusam et justo duo dolores et ea rebum。 Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet。 Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua。在 vero eos et accusam et justo duo dolores et ea rebum。 Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet。
【问题讨论】:
-
Don't know what to write further...一些更详细的调试结果会很好。 “不发送”并不是一个描述。另请参阅 How to Ask 以及如何创建 minimal reproducible example - 我们也不需要大量的 CSS 或 HTML 的无关部分,这样可以稍微降低代码与文本的噪声比。 -
无论如何,通过阅读代码,我可以看到
$name、$kuerzel和$website从未填充到您的代码中。您在提交块之前将它们设置为空,然后......什么都没有。您永远不会尝试从$_POST数组中读取数据。我期待看到$name = $_POST["name"];等。您是否学习过任何有关 PHP 如何处理表单的教程? -
请显示
print_r($_POST)的输出 -
@ArRakin 为什么?我们可以看到表单将提交什么,并且 HTML 都是有序的。阅读我上面的评论,了解真正的问题可能是什么。
-
@ADyson 你是对的!