问题描述
我正在制作一个简单的表单,我面临的问题是当我提交表单时,值仍然存在于该字段中。我希望在SUCCESSFUL提交后清除它。请帮助。
这里是我的代码形式..
< label class =w>计划:< / label>
< option value =>选择一个< / option>
< option value =免费账户>免费账户< / option>
< option value =高级帐户月度>高级帐户月度< / option>
< option value =每年付费帐户>每年付费帐户< / option>
< / select>
< br>
< label class =w>名字:< / label>< input name =firstnametype =textplaceholder =First Namerequired =requiredvalue =<< ;?php echo $ _POST ['firstname'];?>>< br>
< label class =w> Last Name:< / label>< input name =lastnametype =textplaceholder =Last Namerequired =requiredvalue =< ;?php echo $ _POST ['lastname'];?>>< br>
< label class =w>电子邮件ID:< / label>< input name =emailtype =emailplaceholder =输入电子邮件地址required =requiredvalue = <?php echo $ _POST ['email'];?>>< br>
< label class =w>密码:< / label>< input name =passwordtype =passwordplaceholder =********required =required value =<?php echo $ _POST ['password'];?>>< br>
< label class =w>重新输入密码:< / label>< input name =confirmpasswordtype =passwordplaceholder =********required =requiredvalue =<?php echo $ _POST ['confirmpassword'];?>>< br>
< label class =w>街道地址1:< / label>< input name =strtadd1type =textplaceholder =street address firstrequired =requiredvalue = <?php echo $ _POST ['strtadd1'];?>>< br>
< label class =w>街道地址2:< / label>< input name =strtadd2type =textplaceholder =street address secondvalue =<?php echo $ _POST ['strtadd2'];?>>< br>
< label class =w>城市:< / label>< input name =citytype =textplaceholder =Cityrequired =requiredvalue =< ;? php echo $ _POST ['firstname'];?>>< br>
< label class =w>国家:< / label>< select autofocus =id =a1_txtBox1name =countryrequired =requiredplaceholder =select onevalue =<?php echo $ _POST ['country'];?>>
任何帮助都会被appriciated
<$ c解决方案它们保留在字段中,因为您明确告诉PHP使用提交的数据填充表单。 $ c>< input name =firstnametype =textplaceholder =First Namerequired =required
value =<?php echo $ _POST ['firstname'];?> >
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HERE
只要删除它即可,或者如果您希望条件不这样做,如果语句 echo 或者只是清理 $ _ POST 字段。
$ _ POST = array(); //假装什么都没有发布
或者,如果成功,将用户重定向到另一个页面:
header(Location:success.html);
出口; //位置标题被设置,没有意义发送HTML,停止脚本
顺便说一下首选方法。如果您将用户保留在通过 POST 方法到达的页面中,如果他刷新页面,表单将再次提交。
I am making a simple Form the problem i am facing is when i submit the form values still remains in the field. and I want to clear it after SUCCESSFUL submission. Please help.
here is my code for the form..
<label class="w">Plan :</label> <select autofocus="" name="plan" required="required"> <option value="">Select One</option> <option value="FREE Account">FREE Account</option> <option value="Premium Account Monthly">Premium Account Monthly</option> <option value="Premium Account Yearly">Premium Account Yearly</option> </select> <br> <label class="w">First Name :</label><input name="firstname" type="text" placeholder="First Name" required="required" value="<?php echo $_POST['firstname'];?>"><br> <label class="w">Last Name :</label><input name="lastname" type="text" placeholder="Last Name" required="required" value="<?php echo $_POST['lastname'];?>"><br> <label class="w">E-mail ID :</label><input name="email" type="email" placeholder="Enter Email" required="required" value="<?php echo $_POST['email'];?>"><br> <label class="w">Password :</label><input name="password" type="password" placeholder="********" required="required" value="<?php echo $_POST['password'];?>"><br> <label class="w">Re-Enter Password :</label><input name="confirmpassword" type="password" placeholder="********" required="required" value="<?php echo $_POST['confirmpassword'];?>"><br> <label class="w">Street Address 1 :</label><input name="strtadd1" type="text" placeholder="street address first" required="required" value="<?php echo $_POST['strtadd1'];?>"><br> <label class="w">Street Address 2 :</label><input name="strtadd2" type="text" placeholder="street address second" value="<?php echo $_POST['strtadd2'];?>"><br> <label class="w">City :</label><input name="city" type="text" placeholder="City" required="required" value="<?php echo $_POST['firstname'];?>"><br> <label class="w">Country :</label><select autofocus="" id="a1_txtBox1" name="country" required="required" placeholder="select one" value="<?php echo $_POST['country'];?>">
Any help would be appriciated
They remain in the fields because you are explicitly telling PHP to fill the form with the submitted data.
<input name="firstname" type="text" placeholder="First Name" required="required" value="<?php echo $_POST['firstname'];?>"> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HERE
Just remove this, or if you want a condition to not do so make a if statement to that echo or just cleanup the $_POST fields.
$_POST = array(); // lets pretend nothing was posted
Or, if successful, redirect the user to another page:
header("Location: success.html"); exit; // Location header is set, pointless to send HTML, stop the script
Which by the way is the prefered method. If you keep the user in a page that was reached through a POST method, if he refreshes the page the form will be submitted again.
这篇关于成功提交php表单后清除表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!