Hallo Zusammen,
ich bin gerade dabei eine Gästeliste zu erstellen, jedoch habe zuvor gar nichts mit PHP programmiert - ich bin PHP Anfänger )
DANKE IM VORAUS
Hier ist Code:
	
	
	
		
				
			ich bin gerade dabei eine Gästeliste zu erstellen, jedoch habe zuvor gar nichts mit PHP programmiert - ich bin PHP Anfänger )
DANKE IM VORAUS
Hier ist Code:
		PHP:
	
	<?php
echo '<form action="" method="POST">';
$ort = isset($_POST['ort']) ? trim($_POST['ort']) : "";
$anzahl = isset($_POST['anzahl']) ? trim($_POST['anzahl']) : "";
$anlass = isset($_POST['anlass']) ? trim($_POST['anlass']) : "";
$date = isset($_POST['date']) ? trim($_POST['date']) : "";
/////// Schritt 1
if (empty($ort) || empty($anzahl) || empty($anlass)) {
    // Anlass
    if (empty($anlass)) {
        if ($_POST['schon_mal_abgesendet'] == "ja" ) {
            echo "<p>* Bitte Anlass auswählen</p>";
        }
    }
    echo '<p>Anlass: ';
    $select=array('','Geburtstag','Hochzeit','Konferenz');
    echo '<select name="anlass">';
    foreach ($select as $var){
        echo '<option value="'.$var.'">'.$var.'</option>';
    }
    echo '</select>';
    echo "<br><br>";
    // Datum
    if (empty($date)) {
        if ( $_POST['schon_mal_abgesendet'] == "ja" ) {
            echo "<p>* Bitte Datum auswählen</p>";
        }
    }
    echo 'Datum: ';
    echo '<input type="date" name="date" value="';
    echo $ort;
    echo '" size="35" maxlength="60">';
    echo "<br><br>";
    // Ort
    if (empty($ort)) {
        if ( $_POST['schon_mal_abgesendet'] == "ja" ) {
            echo "<p>* Bitte Feld Ort ausfüllen</p>";
        }
    }
    echo 'Ort: ';
    echo '<input type="text" name="ort" value="';
    echo htmlspecialchars($ort);
    echo '" size="20" maxlength="60">';
    echo "<br><br>";
    // Anzahl
    if (empty($anzahl)) {
        if ( $_POST['schon_mal_abgesendet'] == "ja" ) {
            echo "<p>* Bitte anzahl der Gäste eingeben</p>";
        }
    }
    echo 'Anzahl der Gäste: ';
    echo '<input type="number" name="anzahl" value="';
    echo $anzahl;
    echo '" size="4" maxlength="4">';
    echo "<br><br>";
    echo '<input type="hidden" name="schon_mal_abgesendet" value="ja">';
    echo '<br>';
    echo '<input type="Submit" name="" value="weiter">';
    echo '</form>';
    exit;
}
/////// Schritt 2
elseif (isset($_POST['anlass']) || isset($_POST['datum']) || isset($_POST['ort']) || $_POST['subject'] == "")
{
    echo "Anlass: " . $anlass . "<br>";
    echo "Datum: " . $date . "<br>";
    echo "Ort: " . $ort . "<br>";
    echo "Anzahl der Gäste: " . $anzahl . "<br>";
        if (( $_POST['subject'] == "" ) && ( $_POST['schon_zweimal_abgesendet'] == "ja" ))
        {
            // Punkt 5: Fehlermeldung - Feld Nachname ausfüllen
            echo "<p>Hinweis: Bitte Feld Gast ausfüllen</p>";
        }
        $start = 1;
        $stop = $_POST['anzahl'];
        for ($count = $start; $count <= $stop; $count++) {
            // Punkt 6: Feld "zeichnen" für Nachname
            echo "<p>  $count  Gast: ";
            ?><input type="text" name="subject"> <br><?php
        }
        echo '<input type="hidden" name="schon_zweimal_abgesendet" value="ja">';
        echo '<br>';
        echo '<input type="submit" name="vorschau" value="Weiter zur Vorschau">';
    echo '</form>';
    exit;
    }
/////// Schritt 3
    else  {
        echo "Vorschau:";
        echo "Anlass: " . $anlass . "<br>";
        echo "Datum: " . $date . "<br>";
        echo "Ort: " . $ort . "<br>";
        echo "Anzahl der Gäste: " . $anzahl . "<br>";
        $text = $_POST['subject'];
        $text = explode(" ", $text);
        natCaseSort($text);
        foreach ($text as $element) {
            echo $element . "<br>";
        }
    }
        $error = false;
    // Alle POST-Daten mit foreach() auslesen und überprüfen
        foreach ($_POST as $field => $content) {
            if (empty($content)) {
                echo "Das Feld $field enthält keinen Text!<br />";
                $error = true;
            }
        }
        if (!$error) {
            echo "Ort: " . $_POST["ort"] . "<br>"
                . "Anzahl Gäste:" . $_POST["anzahl"] . "<br>" . "Gäste:" . $_POST["subject"];
            // Dateinhalt wird gelöscht
            file_put_contents("myfile.json", "");
            // Alle POST-Daten mit foreach() auslesen und im JSON-Format speichern
            foreach ($_POST as $field => $content) {
                if (!empty($content)) {
                    $json = json_encode($content);
                    file_put_contents("myfile.json", $json, FILE_APPEND);
                }
            }
        }
	
			
				Zuletzt bearbeitet: