簡體   English   中英

聯系表格中未聲明的php變量

[英]undeclared php variable in contact form

我在使用簡單的聯系表時遇到問題。

我得到的錯誤是:

注意:未定義索引:第 29 行 contact.php 中的術語
注意力! 您必須選中隱私政策框才能接受我們的條款。

代碼:

if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");

$name     = $_POST['name'];
$email    = $_POST['email'];
$comments = $_POST['comments'];
$terms    = $_POST['terms'];     // <---- line 29

if(trim($terms) == '') {
    echo '<div class="alert error"><div class="msg">Attention! You have to check 
        the Privacy Policy box to accept our terms.</div></div>';
    exit();
}

if(trim($comments) == '') {
    echo '<div class="alert error"><div class="msg">Attention! Please enter your 
        message.</div></div>';
    exit();
} 

if(get_magic_quotes_gpc()) {
    $comments = stripslashes($comments);
}

模板文件如下:

<form action="<?php echo $this->config->get('config_url').'ajax/contact.php' ?>" method="post" id="contact_form" enctype="multipart/form-data">
    <table>
        <tr>
            <td>
                <label for="name"><?php echo $entry_name; ?></label>
                <input type="text" name="name" id="name" style="margin-right:20px" value="<?php echo $name; ?>" />
                <?php if ($error_name) { ?>
                <span class="error"><?php echo $error_name; ?></span>
                <?php } ?>
            </td>
            <td>
                <label for="email"><?php echo $entry_email; ?></label>
                <input type="text" name="email" id="email" value="<?php echo $email; ?>" />
                <?php if ($error_email) { ?>
                <span class="error"><?php echo $error_email; ?></span>
                <?php } ?>  
            </td>
        </tr>
    </table>

    <label for="enquiry"><?php echo $entry_enquiry; ?></label>
    <textarea name="enquiry" id="enquiry" cols="30" rows="5"><?php echo $enquiry; ?></textarea>
    <?php if ($error_enquiry) { ?>
    <span class="error"><?php echo $error_enquiry; ?></span>
    <?php } ?>

    <input type="checkbox" name="terms" value="<?php echo $terms; ?>" />
    <label for="terms">Tick this box to confirm you comply with our <a href="/privacy-policy/">Privacy Terms</a></label>

    <input type="submit" id="submit" value="<?php echo $button_continue; ?>" class="button dark-bt" />
</form>

試試這個:

$terms    = isset($_POST['terms']) ? $_POST['terms'] : '';

只有當用戶在表單中選中它時,您才會獲得復選框字段。

所以,總是像這樣檢查復選框單選按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM