如何通过在html中提交表单来防止表单被清空?

编程入门 行业动态 更新时间:2024-10-27 12:38:44
本文介绍了如何通过在html中提交表单来防止表单被清空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在写一个使用php和html的表单。 此表单具有验证控制。 当我提交表单时,所有的文本框都变空了,如果用户填写了例如5个输入中的3个,因为如果他/她现在必须再次填充那3个输入。 如何通过提交表单来阻止表单清空输入?

I'm writing a form in using php and html. This form has validation control. when I submit the form all the textboxes get empty and if the user has filled for example 3 of 5 inputs , because if those two inputs he/she now has to fill those 3 inputs again. How can I prevent the form from emptying the inputs by submitting the form?

推荐答案

如果您的验证脚本和表单代码位于同一个文件中,您可以将$ _POST值放入表单中。

If you validation script and form code are in this same file you can just put $_POST values into form.

<?php $field1 = ''; $field2 = ''; ... $field5 = ''; if($_SERVER['REQUEST_METHOD']=="POST"){ $field1 = $_POST['field1']; $field2 = $_POST['field2']; ... $field5 = $_POST['field5']; if(validation is true){ //do something } } ?> <form method="post"> <input type="text" name="field1" value="<?= $field1 ?>" > <input type="text" name="field2" value="<?= $field2 ?>" > ... <input type="text" name="field5" value="<?= $field5 ?>" > <input type="submit" value="submit" > </form>

在评论RiggsFolly后编辑。

EDITED after comment RiggsFolly.

更多推荐

如何通过在html中提交表单来防止表单被清空?

本文发布于:2023-10-11 13:54:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481887.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   清空   html

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!