Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.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 按提交按钮时HTML输入字段不保存文本?_Php_Javascript_Html_Forms - Fatal编程技术网

Php 按提交按钮时HTML输入字段不保存文本?

Php 按提交按钮时HTML输入字段不保存文本?,php,javascript,html,forms,Php,Javascript,Html,Forms,我有点被困在如何正确验证这个表单上了。实际上,这是一种工作方式,但当我输入正确/错误的内容,然后按提交按钮时,文本不会保存在输入字段中,这会使我再次输入所有内容。 我是php的noob&这里有一些伟大的人帮助我用php验证表单。 另外,我想知道,是否可以同时使用JS和php来验证表单? 如果用户禁用了js,我将在客户端使用validate插件,在服务器端使用php。 如果你不介意的话,请检查一下表格,如果可以的话。。 顺便说一句,当php检查表单时,请禁用js以查看问题。 谢谢你抽出时间 <

我有点被困在如何正确验证这个表单上了。实际上,这是一种工作方式,但当我输入正确/错误的内容,然后按提交按钮时,文本不会保存在输入字段中,这会使我再次输入所有内容。 我是php的noob&这里有一些伟大的人帮助我用php验证表单。 另外,我想知道,是否可以同时使用JS和php来验证表单? 如果用户禁用了js,我将在客户端使用validate插件,在服务器端使用php。 如果你不介意的话,请检查一下表格,如果可以的话。。 顺便说一句,当php检查表单时,请禁用js以查看问题。 谢谢你抽出时间

<title>FormTest</title>
        <link rel="stylesheet" type="text/css" href="css.css"/>

        <style type="text/css">
            .formerrors li{color:yellow;
                font-size:14px;
                font-weight:lighter;
                font-family:Tahoma, Geneva, sans-serif;}


        </style>
    </head>
    <body>
<div id="contact">
    <h1 class="heading1"> Contact:</h1>
        <form name="contact" action="" method="post">

            <label for="YourName">Your Name:</label>
            <input type="text" name="name" class="required" />

            <label for="YourEmail">Your Email:</label>
            <input type="text" name="email" class="required"/>

            <label for="Subject">Subject:</label>
            <input type="text" name="subject" class="required"  />

            <label for="YourMessage">Your Message:</label>
            <textarea  name="message" class="required"></textarea>
            <p class="c3">10 + 5 =<input type="text" name="answerbox" id="answerbox" /></p>

        <fieldset>
            <input type="submit" name="submit" id="submit" value="Send" class="required"/>
            <input type="reset" id="reset" value="Reset"/>      
        </fieldset>
<?php
    if(isset($_POST['submit'])){
    $name = trim($_POST["name"]);
    $email = trim($_POST["email"]);
    $subject = trim($_POST["subject"]);
    $message = trim($_POST["message"]);
    $answerbox = trim($_POST["answerbox"]);
    if(empty($_POST['name'])){
        echo "<div class='formerrors'><li>Please type your name.</li></div>";
    } else {
        if (ctype_alpha($name) === false) {
        echo "<div class='formerrors'><li>Your name only contain letters!</li></div>";
        }
    }


    if(empty($_POST['email'])){
        echo "<div class='formerrors'><li>You've forgot to type your email address.</li></div>";
    } else{
        if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
            echo "<div class='formerrors'><li>Your email is not valid, please check.</li></div>";
        }
    }
    if(empty($_POST['subject'])){
        echo "<div class='formerrors'><li>Please type a subject.</li></div>";
    }
    if(empty($_POST['message'])){
        echo "<div class='formerrors'><li>You've forgot to type your message.</li></div>";
    }
    if(empty($_POST['answerbox'])){
        echo "<div class='formerrors'><li>Please answer the math question.</li></div>";
    }   else
    if($answerbox != 15){
            echo "<div class='formerrors'><li>Answer is not correct.</li></div>";
    }
    else{
        $headers =  'From: '.$email. "\r\n" .
        'Reply-To: '.$email . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
        mail('me@mymail.me',$subject,$message,$headers);
        print "Your message was sent successfully";
    }
}


?>
    </form>
</div><!--contact-->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.validate.min.js"></script>
<script type="text/javascript">
            $(document).ready(function() {
                jQuery.validator.addMethod("lettersonly", function(value, element) 
                            {return this.optional(element) || /^[a-z]+$/i.test(value);
                        }, "Letters only please.");

                      $("form").validate({

                        rules:{
                            name: {required: true,
                                maxlength:30,
                                lettersonly: true,},


                            email: {required: true,
                                email: true,
                                minlength: 5,
                                maxlength:40},              

                        answerbox: {required: true,
                                max: 15,
                                min: 15},
                        },

                      });
                    });

</script>


    </body>
</html>
FormTest
颜色:黄色;
字体大小:14px;
字体重量:较轻;
字体系列:Tahoma,日内瓦,无衬线;}
联系人:
你的名字:
您的电子邮件:
主题:
您的留言:

10+5=


当站点重新加载表单时,表单将被清除

你必须自己填写

如果您有如下输入字段:

<input type="text" name="test" id="test" />

您可以这样做:

<input type="text" name="test" id="test" value="<?= isset($_POST['test']) ? $_POST['test'] : '' ?>" />
Name:input type=“text”Name=“Name”value=php echo$Name

保持价值:--


值=?php echo$name

请不要在此处添加潜在的恶意压缩附件。发布问题中的代码。嗨,不,它不是恶意的,不包含任何病毒或类似的东西,我刚刚上传,只是为了视觉效果。我现在就发布代码,你可以这样写:
他说“潜在恶意”,这里有什么问题?提交应该做到这一点,你想要实现什么?嗨,谢谢你的帮助,它现在可以工作了..但是如何将它从文本区域字段和应答框输入中删除?嗨,谢谢你的帮助,它现在可以工作了。但是如何将其从文本区域字段和应答框输入中删除?如果您不想将字段设置为与应答框类似的字段,则可以像以前一样更改它,而无需设置值
<input type="text" name="test2" id="test2" value="Hello" />
<input type="text" name="test2" id="test2" value="<?= isset($_POST['test2']) ? $_POST['test2'] : 'Hello' ?>" />
<textarea name="testtxt" id="testtxt"></textarea>
<textarea name="testtxt" id="testtxt"><?= isset($_POST['testtxt']) ? $_POST['testtxt'] : '' ?></textarea>