[英]Auto submit form on page load
I'm having a bit of trouble with my current issue.我目前的问题有点麻烦。 Any help would be greatly appreciated.
任何帮助将不胜感激。
I have a step in a 'signup process' which I don't need anymore, but I don't have time to reconfigure the entire process so I'm trying to auto submit the form on page load so it will basically skip over this step.我在“注册过程”中有一个我不再需要的步骤,但我没有时间重新配置整个过程所以我试图在页面加载时自动提交表单所以它基本上会跳过这个步。 Any thoughts?
有什么想法吗?
EDIT: Sorry, I should mention, originally there were two submit options, I got rid of one, now I just want to submit the 'mem_type' option on page load.编辑:抱歉,我应该提一下,最初有两个提交选项,我去掉了一个,现在我只想在页面加载时提交“mem_type”选项。 not sure if that makes much of a difference.
不确定这是否有很大的不同。
<form method=post action="<?=$base_href.url("signup")?>" name="member_signup">
<input type=hidden name="process" value="facility_info">
<input type=hidden name="create_order" value="true">
<?php
foreach ($_POST as $k=>$d) {
if ($k === 'textarea') continue;
echo "<input type=hidden name=\"".strip_tags($k)."\" value=\"".strip_tags($d)."\">";
}
?>
<input type="submit" value="submit" name="mem_type" border="0">
</form>
Try this On window load submit your form.试试这个 On window load 提交你的表单。
window.onload = function(){
document.forms['member_signup'].submit();
}
您可以在页面加载时自动提交任何表单,只需将一段 javascript 代码添加到您的 body 标记中,引用表单名称,如下所示......
<body onload="document.form1.submit()">
Add the following to Body
tag,将以下内容添加到
Body
标签中,
<body onload="document.forms['member_signup'].submit()">
and give name
attribute to your Form
.并为您的
Form
提供name
属性。
<form method="POST" action="" name="member_signup">
If your form
doesn't have an id
you can use,如果您的
form
没有您可以使用的id
,
<body onload="document.forms[0].submit()">
This will submit the first form found on the page.这将提交页面上找到的第一个表单。
This is the way it worked for me, because with other methods the form was sent empty:这就是它对我有用的方式,因为使用其他方法,表单被发送为空:
<form name="yourform" id="yourform" method="POST" action="yourpage.html">
<input type=hidden name="data" value="yourdata">
<input type="submit" id="send" name="send" value="Send">
</form>
<script>
document.addEventListener("DOMContentLoaded", function(event) {
document.createElement('form').submit.call(document.getElementById('yourform'));
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.