联系表格"Error: all fields are required"



我正在尝试使联系人表单工作,但我总是收到错误:"错误:所有字段都是必需的"。我真的不知道问题在哪里,所以任何帮助都会很好。

谢谢Mat

PHP:

<?php 
$errors = '';
$myemail = 'yo@example.com';
if(empty($_POST['Email']))
{
    $errors .= "n Error: all fields are required";
}
$nom = $_POST['nom']; 
$prenom = $_POST['prenom']; 
$email_address = $_POST['email']; 
$sujet = $_POST['sujet']; 
$message = $_POST['message']; 
if (!preg_match(
"/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i", 
$email_address))
{
    $errors .= "n Error: Invalid email address";
}
if( empty($errors))
{
    $to = 'yo@example.com';
    $email_subject = "Contact form submission from Defiscalisation Andorre: $username";
    $email_body = "You have received a new message. ".
    " Here are the details:n Nom: $nom n Prénom: $prenom n Email: $email_address n Sujet n $sujet n Message : n $message"; 
    $headers = "From: $ton"; 
    $headers .= "Reply-To: $email_address";
    mail($to,$email_subject,$email_body,$headers);
    //redirect to the 'thank you' page
    header('Location: thanks.html');
} 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
    <title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>

</body>
</html>

HTML:

            <!-- #contact-form -->
            <form id="contact-form" name="contact-form" method="post" action="contact.php">
                <div class="row-fluid">
                    <p class="span6"><input id="nom" name="nom" type="text" tabindex="1" value="" placeholder="Nom"></p>
                    <p class="span6"><input id="prenom" name="prenom" type="text" tabindex="2" value="" placeholder="Prénom"></p>
                </div>
                <div class="row-fluid">
                    <p class="span6"><input id="email" name="email" type="text" tabindex="2" value="" placeholder="E-mail"></p>
                        <p class="span6"><input id="sujet" name="sujet" type="text" tabindex="1" value="" placeholder="Sujet de votre demande"></p>
            </div>
                <div class="row">
                    <p class="span6"><textarea id="message" name="message" tabindex="4" rows="6" placeholder="Message"></textarea></p>
                </div>
                <div class="row">
                    <div class="span2">
                        <button id="sending" type="submit" class="btn btn-embossed btn-large btn-primary" data-send="Envoi...">Envoyer</button>
                    </div>
                </div>
            </form>

Javascript/jQuery:

/*===========================================================*/
/*  Contact Form
/*===========================================================*/ 
$('#contact-form').validate({
rules: {
    nom: {
        minlength: 6,
        required: true
    },
    prenom: {
        minlength: 6,
        required: true
    },
    email: {
        required: true,
        email: true
    },
    sujet: {
        minlength: 10,
        required: true
    },
    message: {
        minlength: 10,
        required: true
        }
    },
    highlight: function(element) {
        $(element).closest('.control-group').removeClass('success').addClass('error');
    },
    success: function(element) {
        element
        .text('OK!').addClass('valid')
        .closest('.control-group').removeClass('error').addClass('success');
    }
});

对于同一变量或元素,您不能在整个代码中在大写字母和小写字母之间切换。你只需要决定其中一个!:)

更改

if(empty($_POST['Email']))

if(empty($_POST['email']))

相关内容

  • 没有找到相关文章

最新更新