提交后保留表单值


keep form value after submit it

我知道有很多像这样的问题,我在网上找到了1000个答案,但没有一个与我的代码一起工作:(所以有人可以帮助我如何保持电子邮件的价值后提交?

        <form name="login-registration" onSubmit="return validateForm()" method="post" action="" >
            <label>Email</label>
            <input type="email" name="emailinput" id="emailinput" value ="" />
            <p id="emptyEmail" class="hidden">Email field is required</p>
            <p id="invalidEmail" class="hidden">Email you insert is invalid!</p>
            <label>Your password</label>
            <input type="password" name="pswinput" id="pswinput" value=""/>
            <p id="pswMinMax" class="hidden">Password should be from 4 to 8 caracters</p>
            <p id="pswLettNum" class="hidden">Password should be letters and numbers. No special caracters are allow</p>
            <label>Repeat password</label>
            <input type="password" name="pswrepeatinput" id="pswrepeatinput" value="" onblur="isValidPswRep()"/>
            <p id="pswR" class="hidden">Your passwords is different</p>
            <input type="checkbox" id="policy" name="policy" value="policy" /> <label>I agree</label>
            <p id="checkN" class="hidden">You must agree to our term</p>
            <input type="submit" name="submit" value="Login" />
        </form>

我试着写一些代码:

<input type="email" name="emailinput" id="emailinput" value = "<?php echo htmlspecialchars($_GET['lastname']); ?>" />

但是php行只是显示在字段输入中。

尝试使用$_POST['lastname']代替$_GET['lastname']

1)如果我没有错的话,我在上面的代码中没有看到任何name="lastname"的字段。

2)使用$_POST,因为你是张贴你的表单数据与方法="post"

假设您的文件有.php作为扩展名,php安装在您的服务器上,我希望您注意到您有一个错误,因为您使用了POST形式,而当您将value应用于您的输入字段时,您正在尝试使用$_GET。此外,您没有将lastname分配给任何输入字段,因此使用emailinput,因为您应用于此字段name="emailinput"。你应该把htmlspecialchars($_GET['emailinput']);改成htmlspecialchars($_POST['emailinput']);

所以你的代码应该是这样的
<input type="email" name="emailinput" id="emailinput" value = "<?php echo htmlspecialchars($_POST['emailinput']); ?>" />

这应该打印你的变量在你的输入字段

这里至少有两个问题。

  1. php内联显示的事实表明,要么你有错误的文件扩展名(如建议的注释),要么文件不包括在你的"知道如何阅读php"(因为缺乏更好的方式来表达,我的英语不完美)目录。

  2. 当你发送一个帖子时,你回一个get(如其他答案所建议的)

也……为什么你的问题有JS标签(抱歉大写,想确保它突出)?