Jump to content
×
×
  • Create New...

Lorem Ipsum is simply dummy text

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

Test Test

Lorem Ipsum is simply dummy text

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

Test Test

Lorem Ipsum is simply dummy text

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

Test Test

Lorem Ipsum is simply dummy text

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

Test Test

Lorem Ipsum is simply dummy text

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

Test Test

  • Bu Alana Reklam Verebilirsiniz
    Bu Alana Reklam Verebilirsiniz

Form Kontrolü Yapma Örneği Ve Kodları | PHP

Rate this topic


serverIR

Recommended Posts

Form Kontrolü Yapma Örneği Ve Kodları | PHP
  • Members

PHP – Zorunlu Alanlar

Önceki sayfadaki doğrulama kuralları tablosundan “Ad”, “E-posta” ve “Cinsiyet” alanlarının zorunlu olduğunu görüyoruz. Bu alanlar boş olamaz ve HTML formunda doldurulması gerekir.

 

PHP-Zorunlu-Alan-Kontrolü.png

 

$isimHata, $emailHata, $cinsHata hata alanları var. Bu hata değişkenleri, gerekli alanlar için hata iletileri içerir. Ayrıca her $_POST değişkeni için bir if else deyimi ekledik. Bu, $ _POST değişkeninin boş olup olmadığını kontrol eder (PHP empty() işleviyle). Boşsa, farklı hata değişkenlerinde bir hata mesajı saklanır ve boş değilse, kullanıcı giriş verilerini test_input() işleviyle gönderir:

 

<?php
function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
  }
 
// alanların tanımlanması
$isimHata = $emailHata = $cinsHata ="";
$isim = $email = $cins = $yorum = "";
 
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["isim"])) {
    $isimHata = "İsim Alanı Zorunludur";
  } else {
    $isim = test_input($_POST["isim"]);
  }
 
  if (empty($_POST["email"])) {
    $emailHata = "Email Alanı Zorunludur";
  } else {
    $email = test_input($_POST["email"]);
  }
 
  if (empty($_POST["yorum"])) {
    $comment = "";
  } else {
    $yorum = test_input($_POST["yorum"]);
  }
 
  if (empty($_POST["cins"])) {
    $cinsHata = "Cinsiyet Alanı Zorunludur";
  } else {
    $cins = test_input($_POST["cins"]);
  }
 
}
?>

 

PHP – Hata İletilerini Görüntüleme

Daha sonra HTML formunda, her gerekli alandan sonra küçük bir komut dosyası ekliyoruz; bu, gerekirse doğru hata iletisini oluşturur (yani, kullanıcı gerekli alanları doldurmadan formu göndermeye çalışırsa):

<html>
<head>
    <style>
    .error{
        color:red;
    }
    </style>
</head>
<body>
<form method="post" action="<?=$_SERVER["PHP_SELF"]?>">
 
İsim: <input type="text" name="isim">
<span class="error">* <?php echo $isimHata;?></span>
<br><br>
E-mail:
<input type="text" name="email">
<span class="error">* <?php echo $emailHata;?></span>
<br><br>
Yorum: <textarea name="yorum" rows="5" cols="40"></textarea>
<br><br>
Cinsiyet:
<input type="radio" name="cins" value="kadın">Kadın
<input type="radio" name="cins" value="erkek">Erkek
<input type="radio" name="cins" value="bos">Belirtmiyor
<span class="error">* <?php echo $cinsHata;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
 
</form>
</body>
</html>

 

Kodların birleştirilmiş Hali

 

<?php
function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
  }
 
// alanların tanımlanması
$isimHata = $emailHata = $cinsHata ="";
$isim = $email = $cins = $yorum = "";
 
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["isim"])) {
    $isimHata = "İsim Alanı Zorunludur";
  } else {
    $isim = test_input($_POST["isim"]);
  }
 
  if (empty($_POST["email"])) {
    $emailHata = "Email Alanı Zorunludur";
  } else {
    $email = test_input($_POST["email"]);
  }
 
  if (empty($_POST["yorum"])) {
    $comment = "";
  } else {
    $yorum = test_input($_POST["yorum"]);
  }
 
  if (empty($_POST["cins"])) {
    $cinsHata = "Cinsiyet Alanı Zorunludur";
  } else {
    $cins = test_input($_POST["cins"]);
  }
 
}
?>
<html>
<head>
    <style>
    .error{
        color:red;
    }
    </style>
</head>
<body>
<form method="post" action="<?=$_SERVER["PHP_SELF"]?>">
 
İsim: <input type="text" name="isim">
<span class="error">* <?php echo $isimHata;?></span>
<br><br>
E-mail:
<input type="text" name="email">
<span class="error">* <?php echo $emailHata;?></span>
<br><br>
Yorum: <textarea name="yorum" rows="5" cols="40"></textarea>
<br><br>
Cinsiyet:
<input type="radio" name="cins" value="kadın">Kadın
<input type="radio" name="cins" value="erkek">Erkek
<input type="radio" name="cins" value="bos">Belirtmiyor
<span class="error">* <?php echo $cinsHata;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
 
</form>
</body>
</html>

 

----------------------------------------------------------------------------

Link to comment
https://weblep.com/topic/197-form-kontrol%C3%BC-yapma-%C3%B6rne%C4%9Fi-ve-kodlar%C4%B1-php/
Share on other sites


Konu Altı Reklam 1
Konu Altı Reklam 2
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...