【问题标题】:This auto submit form doesn't work (sometimes!)此自动提交表单不起作用(有时!)
【发布时间】:2014-07-09 03:52:19
【问题描述】:

这很奇怪。当我直接打开它时,这段代码运行良好——但如果我运行它之前的网页,它就不行。这段代码是一个确认页面,我想在结帐过程中跳转-我有我的所有字段,我不需要再次要求用户确认,所以我直接将她发送到结帐,发送所有的值字段。

再次,当我从另一个表单帖子到达此页面时,它不起作用--尽管发送到此页面的其他字段或对象都没有像表单那样被调用--。有什么想法吗?

<?php include 'security.php' ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
<title>Secure Acceptance - Payment Form</title>
    <link rel="stylesheet" type="text/css" href="payment.css"/>
</head>

<body>

<?php
    foreach($_REQUEST as $name => $value) {
        $params[$name] = $value;
    }
?>
<p>Redirecting to Secure Server...</p>

<form action="https://testsecureacceptance.cybersource.com/pay" method="post" id="formulario" name="formulario" />

    <?php
        foreach($params as $name => $value) {
            echo "<input type=\"hidden\" id=\"" . $name . "\" name=\"" . $name . "\" value=\"" . $value . "\"/>\n";
        }

        echo "<input type=\"hidden\" id=\"signature\" name=\"signature\" value=\"" . sign($params) . "\"/>\n";
    ?>

<input type="submit" id="boton" name="boton" value="Ir a Checkout >>"/>

</form>

<script type = "text/javascript">
    document.getElementById('formulario').submit();
</script>

</body>
</html>

【问题讨论】:

  • 尝试使用 'setTimeout(function(){ /* your code */ , 1000}',当 javascript 渲染时表单可能没有准备好
  • 您的$params 是否有$name 的“提交”?如果是这样,你已经劫持了 document.form.submit 函数,它不会工作。

标签: javascript php html forms form-submit


【解决方案1】:

您可以使用 JavaScript setTimeout 方法在页面加载时延迟提交功能,或者您也可以使用 jQuery 等待文档加载,然后您可以触发表单提交功能: JS:

setTimeout(function(){
 document.getElementById('formulario').submit();
},1000);

jQuery:

$(document).ready(function(){
  $('#formulario').submit();
})

【讨论】:

  • 由于javascript函数调用在文档正文的末尾,所以不需要这样做。
猜你喜欢
  • 2011-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-28
  • 2016-04-06
相关资源
最近更新 更多