Advertisement
caparol6991

Untitled

Dec 7th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.30 KB | None | 0 0
  1. <head>
  2. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  3. </head>
  4.  
  5. <?php
  6. $imie = "";
  7. $nazwisko = "";
  8. $ulica = "";
  9. $miasto = "";
  10. $kod = "";
  11. $numer = "";
  12. $email = "";
  13.  
  14. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  15.   $errors = [];
  16.     if($_POST["imie"] != null){
  17.         if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["imie"]) )|| strlen ($_POST["imie"]) < 3){
  18.         array_push($errors,"Imię musi składać się tylko z liter i mieć co najmniej 3 znaki");
  19.         }
  20.     }else{
  21.         array_push($errors,"Nie podano imienia");
  22.     }
  23.  
  24.     if($_POST["nazwisko"] != null){
  25.   if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["nazwisko"]) )|| strlen ($_POST["nazwisko"]) < 3){
  26.         array_push($errors,"Nazwisko musi składać się tylko z liter i mieć co najmniej 3 znaki");
  27.         }
  28.     }else{
  29.       array_push($errors,"Nie podano nazwiska");
  30.     }
  31.  
  32.     if($_POST["ulica"] != null){
  33.   if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ0-9.\- ]+/", ($_POST["ulica"]) )|| strlen ($_POST["ulica"]) < 3){
  34.         array_push($errors,"Ulica musi się składać z liter, cyfer lub znaków '-','.' i posiadać co najmniej 3 znaki");
  35.         }
  36.     }else{
  37.       array_push($errors,"Nie podano ulicy");
  38.     }
  39.  
  40.     if($_POST["miasto"] != null){
  41.   if(!preg_match("/[A-Za-zżźćńółęąśŻŹĆĄŚĘŁÓŃ]+/", ($_POST["miasto"]) )|| strlen ($_POST["miasto"]) < 3){
  42.         array_push($errors,"Miasto musi składać się tylko z liter i mieć co najmniej 3 znaki");
  43.         }
  44.     }else{
  45.       array_push($errors,"Nie podano miasta");
  46.     }
  47.  
  48.     if($_POST["kod"] != null){
  49.   if(!preg_match("/[0-9]{2}\-[0-9]{3}/", ($_POST["kod"]) )|| strlen ($_POST["kod"]) < 3){
  50.         array_push($errors,"Podaj kod w formacie 00-000");
  51.         }
  52.     }else{
  53.       array_push($errors,"Nie podano kodu pocztowego");
  54.     }
  55.  
  56.     if($_POST["email"] != null){
  57.   if(!preg_match("/^[^0-9][_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/", ($_POST["email"]))){
  58.         array_push($errors,"Podano zły format emailu");
  59.         }
  60.     }else{
  61.       array_push($errors,"Nie podano adresu email");
  62.     }
  63.  
  64.     if($_POST["numer"] != null){
  65.   if(!preg_match("/[0-9]{9}/", ($_POST["numer"]) )|| strlen ($_POST["numer"]) < 3){
  66.         array_push($errors,"Numer musi mieć 9 liczb");
  67.         }
  68.     }else{
  69.       array_push($errors,"Nie podano numeru");
  70.     }
  71.  
  72.     if(count($errors) === 0){
  73.       $myfile = fopen("dane.txt", "w") or die("Nie udało się otworzyć pliku!");
  74.       $txt = "Imię: " . $_POST["imie"] . "\r\n";
  75.       $txt .= "Naziwsko: " . $_POST["nazwisko"] . "\r\n";
  76.       $txt .= "Ulica: " . $_POST["ulica"] . "\r\n";
  77.       $txt .= "Miasto: " . $_POST["miasto"] . "\r\n";
  78.       $txt .= "Kod pocztowy: " . $_POST["kod"] . "\r\n";
  79.       $txt .= "Adres email: " . $_POST["email"] . "\r\n";
  80.       $txt .= "Numer telefonu: " . $_POST["numer"] . "\r\n";
  81.       fwrite($myfile, $txt);
  82.       fclose($myfile);
  83.  
  84.     }
  85.  
  86. }
  87. ?>
  88.  
  89. <body>
  90.   <?php
  91. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  92.   if(count($errors) === 0){
  93.     echo " <div class='alert alert-success' role='alert'> Zapisano pomyślnie! </div>";
  94.   }else{
  95.     echo "<div class='alert alert-danger' role='alert'>";
  96.     foreach($errors as $error){
  97.       echo $error . "<br />";
  98.           $imie = $_POST["imie"];
  99.           $nazwisko = $_POST["nazwisko"];
  100.           $ulica = $_POST["ulica"];
  101.           $miasto = $_POST["miasto"];
  102.           $kod = $_POST["kod"];
  103.           $numer = $_POST["numer"];
  104.           $email = $_POST["email"];
  105.     }
  106.     echo "</div>";
  107.   }
  108.  
  109. }
  110.   ?>
  111. <br>
  112.  
  113. <h2>Wprowadź dane osobowe</h2>
  114.   <form action="index.php" method="post">
  115.  
  116.     <div class="col-md-2">
  117.         <span>Imie</span>
  118.         <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>
  119.     </div>
  120.  
  121.     <div class="col-md-2">
  122.         <span>Nazwisko</span>
  123.         <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>
  124.     </div>
  125.  
  126.     <div class="col-md-2">
  127.         <span>Ulica</span>
  128.         <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>
  129.     </div>
  130.  
  131.     <div class="col-md-2">
  132.         <span>Miasto</span>
  133.         <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>
  134.     </div>
  135.  
  136.     <div class="col-md-2">
  137.         <span>Kod pocztowy</span>
  138.         <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>
  139.     </div>
  140.  
  141.     <div class="col-md-2">
  142.         <span>Adres email</span>
  143.         <input type="email" class="form-control" name="email" placeholder="adres@email.pl" minlength="3" value="<?= $email ?>" required>
  144.     </div>
  145.  
  146.     <div class="col-md-2">
  147.         <span>Numer telefonu</span>
  148.         <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 />
  149.     </div>
  150.  
  151.     <div class="col-md-2">
  152.         <input type="submit" value="Wyslij" />
  153.     </div>
  154. </form>
  155. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement