Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JS自动提交表单 我想添加代码自动提交表单使用JS一旦页面完成加载 我需要它提交输入值太多 当我单击手动自动工作时,提交和验证码响应工作正常,但没有使用输入的g-recaptcha-response值提交 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://www.google.com/recaptcha/api.js?render=<?php echo $captcha_site_key ?>"></script> </head> <form action="check.php" id="myform" method="POST"> <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> <input type="Submit" name="Submit"> </form> <script> grecaptcha.ready(function() { grecaptcha.execute('<?php echo $captcha_site_key ?>', {action:'validate_captcha'}) .then(function(token) { document.getElementById('g-recaptcha-response').value = token; }); }); </script> <script type="text/javascript"> window.onload = function(){ document.getElementById("myform").submit(); } </script> </body> </html>_Javascript_Php_Html - Fatal编程技术网

如何使用JS自动提交表单 我想添加代码自动提交表单使用JS一旦页面完成加载 我需要它提交输入值太多 当我单击手动自动工作时,提交和验证码响应工作正常,但没有使用输入的g-recaptcha-response值提交 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://www.google.com/recaptcha/api.js?render=<?php echo $captcha_site_key ?>"></script> </head> <form action="check.php" id="myform" method="POST"> <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> <input type="Submit" name="Submit"> </form> <script> grecaptcha.ready(function() { grecaptcha.execute('<?php echo $captcha_site_key ?>', {action:'validate_captcha'}) .then(function(token) { document.getElementById('g-recaptcha-response').value = token; }); }); </script> <script type="text/javascript"> window.onload = function(){ document.getElementById("myform").submit(); } </script> </body> </html>

如何使用JS自动提交表单 我想添加代码自动提交表单使用JS一旦页面完成加载 我需要它提交输入值太多 当我单击手动自动工作时,提交和验证码响应工作正常,但没有使用输入的g-recaptcha-response值提交 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://www.google.com/recaptcha/api.js?render=<?php echo $captcha_site_key ?>"></script> </head> <form action="check.php" id="myform" method="POST"> <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"> <input type="Submit" name="Submit"> </form> <script> grecaptcha.ready(function() { grecaptcha.execute('<?php echo $captcha_site_key ?>', {action:'validate_captcha'}) .then(function(token) { document.getElementById('g-recaptcha-response').value = token; }); }); </script> <script type="text/javascript"> window.onload = function(){ document.getElementById("myform").submit(); } </script> </body> </html>,javascript,php,html,Javascript,Php,Html,在Javascript中,使用以下小技巧可以实现您的目标: 使用纯Javascript-这是您提交表单的方式: document.getElementById("YourFormIdHere").submit(); 如果您希望仅在提供验证码时提交该表单,则必须运行If语句 首先停止表单提交,以便在提交验证码之前对其进行评估 document.getElementById("FormIdHere").addEventListener("submit", function(event) {

在Javascript中,使用以下小技巧可以实现您的目标:

使用纯Javascript-这是您提交表单的方式:

  document.getElementById("YourFormIdHere").submit();
如果您希望仅在提供验证码时提交该表单,则必须运行If语句

首先停止表单提交,以便在提交验证码之前对其进行评估

document.getElementById("FormIdHere").addEventListener("submit", function(event) {
  event.preventDefault()
});
从这里,您需要检查验证码值是否已提交。首先尝试获取验证码的值

var Captcha = document.GetElementById("capture ID here").value;

//check if captcha has value
if(Captcha){
    //then submit your form here
    document.getElementById("YourFormIdHere").submit();
}

如果验证码值为空,表单将不会提交,从而强制用户创建验证码。

感谢@Mosia Thabo对我的帮助

JS代码是

解释:-第一个setAttribute'value','token'

然后等待1秒钟,然后提交我的表单


发生什么情况时自动提交?页面何时加载?当单击与表单没有直接关联的内容时?您希望自动提交的依据是什么?我投票结束这个问题,因为堆栈溢出不是一种代码编写服务。你不能只告诉我们你想要什么代码,然后把它放在银盘上交给你;你需要努力,我们会帮你解决你遇到的问题。可能是重复的我很累,尽了最大的努力,但没有完成你的实际尝试,并描述问题。您的表单只有一个recaptcha响应,自动提交没有多大意义,但是captcha响应=null没有得到值检查。这是我的问题。如果它为空,则没有收到值。这意味着你的验证码没有任何价值。但是问题已经得到了回答,因为表单是在页面加载时提交的。请把答案记下来。如果未显示任何值,则未提交任何值,并且该值不再在问题的上下文中。不知何故,验证码没有在页面加载时提交结果。还记得你说过你在检查机器人吗?当我单击“提交手动使用值工作”时,我会在scirpt之前使用它,因为这些都是事件驱动的操作,所以不必担心你把代码放在哪里。。。在之前或之后。但我明白。
<script type="text/javascript">
    document.getElementById('g-recaptcha-response')..setAttribute("value", token);‏

</script>
<script type="text/javascript">
window.onload=function(){ 
    window.setTimeout(document.myform.submit.bind(document.myform), 100);
};
 </script>