简体   繁体   English

如何在没有警告的情况下允许用户重新提交表单

[英]How to allow a user to resubmit a form without a warning

I believe it will be a poor question, because most people wants to prevent a form from beeing resubmited but I'll need the exact opposit of it. 我认为这将是一个很糟糕的问题,因为大多数人都希望阻止重新提交表格,但我需要确切的反对意见。

That means a user should be allowed to reload a page and the form values have to be posted each time (Session Variables are not possible in this cenario) Normally the user gets the annoying warning message of the browser. 这意味着应该允许用户重新加载页面,并且每次都必须发布表单值(在这种情况下,会话变量是不可能的)通常,用户会收到浏览器的烦人警告消息。 Is it possible to turn this warning off or simply resubmit the form (eg. with jQuery) 是否可以关闭此警告或直接重新提交表单(例如,使用jQuery)

Thanks a lot for your help! 非常感谢你的帮助!

You could overwrite alert and empty the function with alert = function(){} . 您可以使用alert = function(){}覆盖alert并清空该函数。 Check this example: 检查以下示例:

 alert("test"); alert = function(){}; alert("test2"); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

You cannot turn off this alert (in a good way), but you can redirect to the same form, with all fields auto-compiled, so if you re-do a submit, it won't ask you a confirm. 您不能(以一种很好的方式)关闭此警报,但是您可以重定向到同一表单,并自动编译所有字段,因此,如果您重新提交,则不会要求您进行确认。 You can redirect with a _GET parameter, and if your code detect this, it will check for all values to insert in the form. 您可以使用_GET参数进行重定向,如果您的代码检测到此参数,它将检查是否将所有值插入到表单中。

Something like this: 像这样:

form.php form.php

<?php
if(!empty($_GET['param'])) {
    /* Pseudo code */
    $data = query_and_fetch("select 'value_1' as field_1 from yourtable WHERE wfield='".escape($_GET['param'])."' ;");
}
?>

<form method='post' action='process.php'>
    <input name='field_1' value='<?=isset($data['field_1']) ? $data['field_1'] : ''?>/>
    <input type='submit' value='submit'/>
</form>

process.php process.php

<?php
header("location: form.php?param=123");
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM