Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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_Html_Forms - Fatal编程技术网

Php 提交页面的联系人表单后,只需刷新页面即可

Php 提交页面的联系人表单后,只需刷新页面即可,php,html,forms,Php,Html,Forms,当我提交这份联系表时,所发生的一切就是页面刷新。未发送任何邮件,也没有错误消息。我是从本地主机发送的,但我已经知道它是有效的,因为我发送了一封带有相同联系方式的电子邮件,但当我添加验证时,它不再有效。我只是很不明白为什么它会刷新 HTML 直接与我们联系 有任何问题没有在会议上回答。 首先,你的value=”“如果不被回音,就不会有太多的功能,可能会给你带来未定义的变量通知;“如果”您已将错误报告设置为捕获和显示,那么您应该在测试期间执行一些操作是您的实际代码;错误报告应该给你一个未定义的持续

当我提交这份联系表时,所发生的一切就是页面刷新。未发送任何邮件,也没有错误消息。我是从本地主机发送的,但我已经知道它是有效的,因为我发送了一封带有相同联系方式的电子邮件,但当我添加验证时,它不再有效。我只是很不明白为什么它会刷新

HTML


直接与我们联系
有任何问题没有在会议上回答。

首先,你的
value=”“
如果不被回音,就不会有太多的功能,可能会给你带来未定义的变量通知;“如果”您已将错误报告设置为捕获和显示,那么您应该在测试期间执行一些操作是您的实际代码;错误报告应该给你一个未定义的持续通知,因为它没有被引用。但是在我进行验证之前,我认为这是正确的方法,设置为捕获和显示,查看HTML源代码并使用
var_dump()
在$\u POST和变量上。哦,它说变量没有声明,但应该声明
<section id="contact">
            <h1 class="section-header">Contact Us Directly</h1>
            <h4 class="text-center">Have any quesitons not answered in the <span><a href="questions.php">Questions Page</a></span>.</h4>
            <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
                <label for="fname">First Name</label>
                <input type="text" id="fname" name="firstname" value="<?php $firstname ?>" placeholder="Your name.." tabindex="1" autofocus> <span class="error"><?php $firstname_error ?></span>
                <label for="lname">Last Name</label>
                <input type="text" id="lname" name="lastname" value="<?php $lastname ?>" placeholder="Your last name.." tabindex="2"> <span class="error"><?php $lastname_error ?></span>
                <label for="email">Email</label>
                <input type="text" id="email" name="email" value="<?php $email ?>" placeholder="Your email.." tabindex="3"> <span class="error"><?php $email_error ?></span>
                <label for="message">Message</label>
                <textarea id="subject" name="message" value="<?php $message ?>" placeholder="Write something.." style="height:200px" tabindex="4"> </textarea> <span class="error"><?php $message_error ?></span>
                <input type="submit" value="Submit" tabindex="5"> <span class="success"><?php $success ?></span> </form>
        </section>
 <?php

  $firstname_error = $lastname_error = $email_error = $message_error = "";
  $firstname = $lastname = $email = $message = $success = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["firstname"])) {
    $firstname_error = "First name is required";
  } else {
    $firstname = test_input($_POST["firstname"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/", $firstname)) {
        $firstname_error = "Only letters and white space allowed";
    }
}

if (empty($_POST["lastname"])) {
    $lastname_error = "Last name is required";
} else {
    $lastname = test_input($_POST["lastname"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$lastname)) {
        $lastname_error = "Only letters and white space allowed";
    }
}

if (empty($_POST["email"])) {
    $email_error = "Email is required";
} else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $email_error = "Invalid email format";
    }
}

if (empty($_POST["message"])) {
    $message_error = "Message is required";
} else {
    $message = test_input($_POST["message"]);
}


if ($firstname_error == '' and $lastname_error == '' and $email_error == '' and $message_error == '' ){
    $Body = "";
    $Body .= "Firstname: ";
    $Body .= $firstname;
    $Body .= "\n";
    $Body .= "Lastname: ";
    $Body .= $lastname;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $message;
    $Body .= "\n";

    $EmailFrom = localhost;
    $EmailTo = "testrepairmail69@gmail.com";
    $Subject = "New Order From tabletscreenfixer.com";
    $success = mail($EmailTo, $Subject, $Body, "From: <$email>");
    if ($success){
        print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
        $firstname = $lastname = $email = $message = '';
    }else{
        print "<meta http-equiv=\"refresh\" content=\"0;URL=contactfail.php\">";
        $firstname = $lastname = $email = $message = '';
    } 
 }
 }
    function test_input($data) {
       $data = trim($data);
       $data = stripslashes($data);
       $data = htmlspecialchars($data);
       return $data;
    }

 ?>