Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <head>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- </head>
- <?php
- $imie = "";
- $nazwisko = "";
- $ulica = "";
- $miasto = "";
- $kod = "";
- $numer = "";
- $email = "";
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- $errors = [];
- if($_POST["imie"] != null){
- if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["imie"]) )|| strlen ($_POST["imie"]) < 3){
- array_push($errors,"Imię musi składać się tylko z liter i mieć co najmniej 3 znaki");
- }
- }else{
- array_push($errors,"Nie podano imienia");
- }
- if($_POST["nazwisko"] != null){
- if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["nazwisko"]) )|| strlen ($_POST["nazwisko"]) < 3){
- array_push($errors,"Nazwisko musi składać się tylko z liter i mieć co najmniej 3 znaki");
- }
- }else{
- array_push($errors,"Nie podano nazwiska");
- }
- if($_POST["ulica"] != null){
- if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ0-9.\- ]+/", ($_POST["ulica"]) )|| strlen ($_POST["ulica"]) < 3){
- array_push($errors,"Ulica musi się składać z liter, cyfer lub znaków '-','.' i posiadać co najmniej 3 znaki");
- }
- }else{
- array_push($errors,"Nie podano ulicy");
- }
- if($_POST["miasto"] != null){
- if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["miasto"]) )|| strlen ($_POST["miasto"]) < 3){
- array_push($errors,"Miasto musi składać się tylko z liter i mieć co najmniej 3 znaki");
- }
- }else{
- array_push($errors,"Nie podano miasta");
- }
- if($_POST["kod"] != null){
- if(!preg_match("/[0-9]{2}\-[0-9]{3}/", ($_POST["kod"]) )|| strlen ($_POST["kod"]) < 3){
- array_push($errors,"Podaj kod w formacie 00-000");
- }
- }else{
- array_push($errors,"Nie podano kodu pocztowego");
- }
- if($_POST["email"] != null){
- if(!preg_match("/^[^0-9][_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", ($_POST["email"]))){
- array_push($errors,"Podano zły format emailu");
- }
- }else{
- array_push($errors,"Nie podano adresu email");
- }
- if($_POST["numer"] != null){
- if(!preg_match("/[0-9]{9}/", ($_POST["numer"]) )|| strlen ($_POST["numer"]) < 3){
- array_push($errors,"Numer musi mieć 9 liczb");
- }
- }else{
- array_push($errors,"Nie podano numeru");
- }
- if(count($errors) === 0){
- $myfile = fopen("dane.txt", "w") or die("Nie udało się otworzyć pliku!");
- $txt = "Imię: " . $_POST["imie"] . "\r\n";
- $txt .= "Naziwsko: " . $_POST["nazwisko"] . "\r\n";
- $txt .= "Ulica: " . $_POST["ulica"] . "\r\n";
- $txt .= "Miasto: " . $_POST["miasto"] . "\r\n";
- $txt .= "Kod pocztowy: " . $_POST["kod"] . "\r\n";
- $txt .= "Adres email: " . $_POST["email"] . "\r\n";
- $txt .= "Numer telefonu: " . $_POST["numer"] . "\r\n";
- fwrite($myfile, $txt);
- fclose($myfile);
- }
- }
- ?>
- <body>
- <?php
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if(count($errors) === 0){
- echo " <div class='alert alert-success' role='alert'> Zapisano pomyślnie! </div>";
- }else{
- echo "<div class='alert alert-danger' role='alert'>";
- foreach($errors as $error){
- echo $error . "<br />";
- $imie = $_POST["imie"];
- $nazwisko = $_POST["nazwisko"];
- $ulica = $_POST["ulica"];
- $miasto = $_POST["miasto"];
- $kod = $_POST["kod"];
- $numer = $_POST["numer"];
- $email = $_POST["email"];
- }
- echo "</div>";
- }
- }
- ?>
- <br>
- <h2>Wprowadź dane osobowe</h2>
- <form action="index.php" method="post">
- <div class="col-md-2">
- <span>Imie</span>
- <input pattern="[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+" oninvalid="setCustomValidity('Imie musi miec co najmniej 3 litery i zawierac tylko znaki.')" oninput="setCustomValidity('')" minlength="3" type="text" class="form-control" name="imie" placeholder="Imie" value="<?= $imie ?>" required>
- </div>
- <div class="col-md-2">
- <span>Nazwisko</span>
- <input pattern="[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+" oninvalid="setCustomValidity('Nazwisko musi miec co najmniej 3 litery i zawierac tylko znaki.')" oninput="setCustomValidity('')" minlength="3" type="text" class="form-control" name="nazwisko" placeholder="Nazwisko" value="<?= $nazwisko ?>" required>
- </div>
- <div class="col-md-2">
- <span>Ulica</span>
- <input pattern="[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+" oninvalid="setCustomValidity('Ulica musi miec co najmniej 3 litery i zawierac tylko a-z,0-9,\'-\' oraz \'.\' ')" oninput="setCustomValidity('')" minlength="3" type="text" class="form-control" name="ulica" placeholder="Ulica" value="<?= $ulica ?>" required>
- </div>
- <div class="col-md-2">
- <span>Miasto</span>
- <input pattern="[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+" oninvalid="setCustomValidity('Miasto musi miec co najmniej 3 litery i zawierac tylko a-z,0-9,\'-\' oraz \'.\' ')" oninput="setCustomValidity('')" minlength="3" type="text" class="form-control" name="miasto" placeholder="Miasto" value="<?= $miasto ?>" required>
- </div>
- <div class="col-md-2">
- <span>Kod pocztowy</span>
- <input pattern="[0-9]{2}[\-][0-9]{3}" oninvalid="setCustomValidity('Wprowadz kod pocztowy w formacie 00-000')" oninput="setCustomValidity('')" type="text" class="form-control" name="kod" placeholder="kod" value="<?= $kod ?>" required>
- </div>
- <div class="col-md-2">
- <span>Adres email</span>
- <input type="email" class="form-control" name="email" placeholder="adres@email.pl" minlength="3" value="<?= $email ?>" required>
- </div>
- <div class="col-md-2">
- <span>Numer telefonu</span>
- <input type="text" pattern="[0-9]{9}" oninvalid="setCustomValidity('Numer musi mieć 9 cyfr')" oninput="setCustomValidity('')" class="form-control" name="numer" placeholder="Numer telefonu" value="<?= $numer ?>" required><br />
- </div>
- <div class="col-md-2">
- <input type="submit" value="Wyslij" />
- </div>
- </form>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement