1

It doesn't send any input when submitting with the button. As far as I can see, the submit-block (isset...) should be fine. But there's nothing in the variables name, kuerzel and website.

Does anybody can help me?

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'>&#xE872;</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">&#xE147;</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">&times;</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>

Don't know what to write further...

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At 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. At 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. At 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.

9
  • Don't know what to write further...some more detailed results of your debugging would be good. "doesn't send" isn't much of a description. See also How to Ask and how to create a minimal reproducible example - we also don't need a mountain of CSS or irrelevant parts of the HTML, so that would reduce the code-to-text noise ratio a bit. Commented Aug 11, 2021 at 16:17
  • Anyway, from reading the code I can see that $name, $kuerzel, and $website are never populated in your code. You set them to empty at the start just before the submit-block and then...nothing. You never attempt to read the data into them from the $_POST array. I'd be expecting to see $name = $_POST["name"]; etc. Have you studied any tutorials on how PHP works with forms? Commented Aug 11, 2021 at 16:22
  • Please show the output of print_r($_POST) Commented Aug 11, 2021 at 16:28
  • @ArRakin why? We can see what the form will submit, and the HTML is all in order. Read my comment above to understand what the real issue is likely to be. Commented Aug 11, 2021 at 16:29
  • @ADyson you are right! Commented Aug 11, 2021 at 16:30

1 Answer 1

1

Anyway, from reading the code I can see that $name, $kuerzel, and $website are never populated in your code. You set them to empty at the start just before the submit-block and then...nothing. You never attempt to read the data into them from the $_POST array. I'd be expecting to see $name = $_POST["name"]; etc. Have you studied any tutorials on how PHP works with forms? –

...solved it for me

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.