Und nochmal ich😀😀
Ich habe jetzt den Code eingerückt.
Komplettiert eingerückter Code:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Formular</title>
</head>
<body>
<?php
$error = '';
$Name = htmlspecialchars ( stripslashes ( trim ( $_POST [ 'name' ] ) ) ) ;
$email = htmlspecialchars ( stripslashes ( trim ( $_POST [ "email" ] ) ) ) ;
if( $_SERVER[ 'REQUEST_METHOD' ] == 'POST' ) {
if( empty( $Name ) ) {
$error = 'Der Name ist ein Pflichtfeld!';
} elseif( ! filter_var($_POST[ 'email' ], FILTER_VALIDATE_EMAIL ) ) {
$error = 'Keine Valide Email';
} else {
echo 'Hallo '
. $Name
.'<br>Der Newsletter wird gesendet an:'
. $email;
}
}
?>
<form action = "<?php echo htmlspecialchars ( $_SERVER [ 'php_self'] ) ; ?> " method = "POST">
<label for = "Name" >Name:</label><input id = "Name" required = "required" type = "text" name = "name" placeholder = "z.b. Erica/Max Mustermann" ><br>
<label for = "Email" >Email:</label><input id = "Email" required = "required" type = "text" name = "email" placeholder = "z.b en@stein.com"><br>
<?php echo '<p>'.$error . '</p>' ; ?> <br>
<input type = "submit" value = "Senden">
</form>
</body>
</html>
af2111