2011-12-11 114 views
0

我試圖與isset()一起使用,將必填字段添加到我的表單中,如下所示,但這足夠嗎?
它只適用於一個字段:ik_wens,因爲它是一個複選框。該表格忽略未完成的文本字段並僅發送電子郵件。
我在做什麼錯?請填寫表單字段

<?php 
    if ( !isset($_POST['naam']) || 
      !isset($_POST['adres']) || 
      !isset($_POST['tel']) || 
      !isset($_POST['datum_gourmet_fondue']) || 
      !isset($_POST['aantal_personen'])|| 
      !isset($_POST['ik_wens'])|| 
      !isset($_POST['graag']) 
     ) { 
     echo 'U heeft niet alle velden ingevuld!'; 
     exit;  
    } 

    $to = '[email protected]'; 
    $onderwerp = " Gourmet/ fonduelijst "; ; 

    $naam = htmlspecialchars($_POST['naam']); 
    $adres = htmlspecialchars($_POST['adres']); 
    $tel = htmlspecialchars($_POST['tel']); 
    $datum_gourmet_fondue = htmlspecialchars($_POST['datum_gourmet_fondue']); 
    $aantal_personen = htmlspecialchars($_POST['aantal_personen']); 
    $wish = $_POST["ik_wens"]; 
    $graag = htmlspecialchars($_POST['graag']); 

    $details = " 
     Onderwerp: $onderwerp\n\n\n 
     Naam: $naam\n\n 
     Adres: $adres\n\n 
     Tel.: $tel \n\n 
     Datum gourmet/ fondue: $datum_gourmet_fondue \n\n 
     Aantal personen: $aantal_personen \n\n 
     Ik wens: $wish \n\n 
     Graag: $graag 
     "; 

    // Send the message 
    $ok = mail($to, $onderwerp, $details); 
    if ($ok) { 
     echo "<p>E-mail is verzonden</p>"; 
    } else { 
     echo "<p>E-Mail is niet verzonden, probeer opnieuw!</p>"; 
    } 
?> 
+0

請注意,並非所有的瀏覽器都支持多行字符串常量。 – Pointy

回答

1

您使用isset,返回true對於存在於形式的所有元素。您需要改爲empty

http://php.net/empty

+0

謝謝!修正了! – kim