Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php代码未呈现引导警报_Php_Validation - Fatal编程技术网

php代码未呈现引导警报

php代码未呈现引导警报,php,validation,Php,Validation,我对编码相当陌生,一直在努力让我的contact_process.php表单在联系人表单的姓名或电子邮件填写错误时显示一条警告消息。由于某些原因,my.alert.alert danger类不会显示,但my.alert.alert成功类会在提交表单后显示。我将if-else语句的结果存储在变量result中,并使用echo显示它。任何帮助都将不胜感激 这是我的密码: <?php // isset function checks if the variable is set or has a

我对编码相当陌生,一直在努力让我的contact_process.php表单在联系人表单的姓名或电子邮件填写错误时显示一条警告消息。由于某些原因,my.alert.alert danger类不会显示,但my.alert.alert成功类会在提交表单后显示。我将if-else语句的结果存储在变量result中,并使用echo显示它。任何帮助都将不胜感激

这是我的密码:

<?php
// isset function checks if the variable is set or has a value 
if (isset($_POST['submit'])) {
    // Declaring the variables 
    $name = $_POST['name'];
    $email = $_POST['email'];
    $date = $_POST['date'];
    $message = $_POST['message'];

    $from = 'Business Name';
    $to = 'byron@gmail.com';
    $subject = 'New Contact';

    // Fills the content of the email
    $body = "From: $name\n Email: $email\n DOB: $date\n Message:\n $message";

    // Checks that the user entered a name 
    if (!$_POST['name']) {
    $errorName = 'Enter your first and last name please';
    }

    // Checks if the user entered a valid email address
    if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
    $errorEmail = 'Only valid email addresses please';  
    }

    // Function checks for errors, if there are none, it sends the form
    if (!$errorName && !$errorEmail) {
        if (mail ($to, $subject, $body, $from)) {
            $result='<div class="alert alert-success" role="alert">Thank you for contacting our business.<br>We will contact you soon.</div>';
        }
        else {
            $result='<div class="alert alert-danger" role="alert">Sorry your message was unsuccessful.<br>Please try again by returning to the contact page.</div>';
        }
    }   
}
?>

<?php include 'header.php'; ?>

<main>

<!-- Echo prints the result of the form being sent or not -->
<?php echo $result; ?>

</main>

<?php include 'footer.php'; ?> 


如果发生错误,您没有返回任何内容为
如果(!$errorName&&!$errorEmail)
添加了一条else语句,它成功了!非常感谢你的帮助。