php
  • html
  • mail-form
  • 2014-03-13 99 views 0 likes 
    0

    我有一個聯繫表單,它發送一個填充了字段的電子郵件。只有當這些字段是空的,並且有一個錯誤信息表明有字段缺失時。問題是errormessage不顯示在頁面上。當聯繫表格失敗時顯示錯誤消息

    這是我的php頁面。

    <?php 
    if (isset($_POST['submit'])) { 
    $body = ''; 
    
    $body .= 'Naam: ' . $_POST['naam'] . "\n"; 
    $body .= 'Telefoon: ' . $_POST['telefoon'] . "\n"; 
    $body .= 'Email: ' . $_POST['email'] . "\n"; 
    $body .= 'Bericht: ' . $_POST['bericht'] . "\n"; 
    $body .= 'Adres: ' . $_POST['adres'] . "\n"; 
    
    if (($_POST['naam'] && $_POST['email'] && $_POST['bericht'] && $_POST['telefoon'] !="")) 
    { 
    mail('[email protected]', 'Contact Form', $body, 'From:  [email protected]'); 
    header("Location: /bedankt.html"); 
    } 
    else 
    { 
    $naamErr = $berichtErr = $emailErr = $telefoonErr = $errormessage = ""; 
    $errormessage = "De volgende velden waren niet ingevuld: "; 
    if($_POST['naam'] == "") 
    { 
    $errormessage .= "naam,"; 
    } 
    if($_POST['bericht'] == "") 
    { 
    $errormessage .= "bericht,"; 
    } 
    if($_POST['email'] == "") 
    { 
    $errormessage .= "email,"; 
    } 
    if($_POST['telefoon'] == "") 
    { 
    $errormessage .= "telefoon"; 
    } 
    
    header("Location: contact.html?errormessage=$errormessage"); 
    } 
    } 
    
    
    ?> 
    

    在重定向的頁面上,我使用$ _GET函數來調用查詢字符串。

    <?php print $_GET["errormessage"];?> 
    

    我做錯了什麼,因爲錯誤消息沒有顯示。

    +0

    define'does not work' –

    +0

    它不顯示錯誤消息 – PatrickJ

    +0

    在contact.html頁面上,如何使用php打印功能? –

    回答

    0

    你不能在html頁面獲得$_GET

    你需要php頁面來做到這一點。

    創建contact.php而不是contact.html。

    ,並嘗試這個辦法:

    header("Location: contact.php?errormessage=$errormessage"); 
    
    1

    如果你正在寫<?php print $_GET["errormessage"];?>,我可以看到你重定向扔頭「contact.html」與下面的代碼header("Location: contact.html?errormessage=$errormessage");

    在HTML頁面中,我們不能使用php $ _GET [「errormessage」]

    相關問題