php 如何在加载页面时提交 HTML 表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15216052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to submit an HTML form on loading the page?
提问by Vinod VT
How to submit this form without using submit button. I want to submit it in loading this form,
如何在不使用提交按钮的情况下提交此表单。我想在加载这个表单时提交它,
<form name="frm1" id="frm1" action="../somePage" method="post">
Please Waite...
<input type="hidden" name="uname" id="uname" value="<?php echo $uname;?>" />
<input type="hidden" name="price" id="price" value="<?php echo $price;?>" />
</form>
采纳答案by Ravinder Singh
Do this :
做这个 :
$(document).ready(function(){
$("#frm1").submit();
});
回答by HNygard
You don't need Jqueryhere! The simplest solutionhere is (based on the answer from charles):
你在这里不需要Jquery!这里最简单的解决方案是(基于查尔斯的回答):
<html>
<body onload="document.frm1.submit()">
<form action="http://www.google.com" name="frm1">
<input type="hidden" name="q" value="Hello world" />
</form>
</body>
</html>
回答by charles
You can try also using below script
您也可以尝试使用以下脚本
<html>
<head>
<script>
function load()
{
document.frm1.submit()
}
</script>
</head>
<body onload="load()">
<form action="http://www.google.com" id="frm1" name="frm1">
<input type="text" value="" />
</form>
</body>
</html>
回答by Deepak Srinivasan
using javascript
使用 JavaScript
<form id="frm1" action="file.php"></form>
<script>document.getElementById('frm1').submit();</script>
回答by Shankar Prakash G
You can do it by using simple one line JavaScript code and also be careful that if JavaScript is turned off it will not work. The below code will do it's job if JavaScript is turned off.
您可以通过使用简单的一行 JavaScript 代码来实现,并且还要注意,如果 JavaScript 被关闭,它将无法工作。如果 JavaScript 关闭,下面的代码将完成它的工作。
Turn off JavaScript and run the code on you own file to know it's full function.(If you turn off JavaScript here, the below Code Snippet will not work)
关闭 JavaScript 并在您自己的文件上运行代码以了解它的完整功能。(如果您在这里关闭 JavaScript,下面的代码片段将不起作用)
.noscript-error {
color: red;
}
<body onload="document.getElementById('payment-form').submit();">
<div align="center">
<h1>
Please Waite... You Will be Redirected Shortly<br/>
Don't Refresh or Press Back
</h1>
</div>
<form method='post' action='acction.php' id='payment-form'>
<input type='hidden' name='field-name' value='field-value'>
<input type='hidden' name='field-name2' value='field-value2'>
<noscript>
<div align="center" class="noscript-error">Sorry, your browser does not support JavaScript!.
<br>Kindly submit it manually
<input type='submit' value='Submit Now' />
</div>
</noscript>
</form>
</body>
回答by Ramesh Moorthy
You missed the closing tag for the input fields, and you can choose any one of the events, ex: onload, onclick etc.
您错过了输入字段的结束标记,您可以选择任一事件,例如:onload、onclick 等。
(a) Onload event:
(a) 加载事件:
<script type="text/javascript">
$(document).ready(function(){
$('#frm1').submit();
});
</script>
(b) Onclick Event:
(b) Onclick 事件:
<form name="frm1" id="frm1" action="../somePage" method="post">
Please Waite...
<input type="hidden" name="uname" id="uname" value=<?php echo $uname;?> />
<input type="hidden" name="price" id="price" value=<?php echo $price;?> />
<input type="text" name="submit" id="submit" value="submit">
</form>
<script type="text/javascript">
$('#submit').click(function(){
$('#frm1').submit();
});
</script>

