简体   繁体   English

paypal 按钮表单不会在 php 文件中自动提交

[英]paypal button form will not auto-submit in php file

I've got a paypal button form in a php file that I'm trying to auto-submit using javascript. It seems like it should be very straight forward, but when I test it, the submit button displays, and I am not automatically re-directed to paypal as expected.我在 php 文件中有一个 paypal 按钮表单,我正在尝试使用 javascript 自动提交。看起来它应该非常简单,但是当我测试它时,提交按钮显示,我不会自动按预期重定向到 paypal。 When I click the submit button I am redirected to paypal and everything looks right.当我点击提交按钮时,我被重定向到 paypal,一切看起来都正确。 I've read through all the similar posts, which is where I found the script I'm trying to use.我已经阅读了所有类似的帖子,这是我找到我正在尝试使用的脚本的地方。 I've been at this for several hours and have tried several different recommendations from other posts but I just can't get it to work.我已经这样做了几个小时,并尝试了其他帖子的几种不同建议,但我就是无法让它发挥作用。 Any assistance would be very appreciated.任何帮助将不胜感激。 The form code (with some values "xxx"'d out for security) and script is shown below.表单代码(为了安全起见带有一些值“xxx”)和脚本如下所示。 Note that some of the field values are populated with php.请注意,某些字段值是用 php.ini 填充的。


<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypalButton" name="paypalButton" target="_top" >
    <input type="hidden" name="cmd" value="_xclick-subscriptions">
    <input type="hidden" name="business" value="xxx">
    <input type="hidden" name="lc" value="US">
    <input type="hidden" name="item_name" value="<?php echo $_SESSION['item_name'];?>">
    <input type="hidden" name="no_note" value="1">
    <input type="hidden" name="no_shipping" value="1">
    <input type="hidden" name="rm" value="1">
    <input type="hidden" name="return" value="http://example.com/sucess.php">
    <input type="hidden" name="cancel_return" value="http://example.com/Cancel.php">
    <input type="hidden" name="src" value="1">
    <input type="hidden" name="a3" value="<?php echo $_SESSION['price'];?>">
    <input type="hidden" name="custom" value="<?php echo $_SESSION['deal_id'].$_SESSION['refresh_token'];?>">
    <input type="hidden" name="p3" value="1">
    <input type="hidden" name="t3" value="<?php echo $_SESSION['t3'];?>">
    <input type="hidden" name="a1" value="<?php echo $_SESSION['a1'];?>">
    <input type="hidden" name="p1" value="1">
    <input type="hidden" name="t1" value="Y">
    <input type="hidden" name="currency_code" value="USD">
    <input type="hidden" name="bn" value="xxx">
    <input type="submit" name="submit">
</form>
<script type="text/javascript">
    document.getElementById('paypalButton').submit(); // SUBMIT FORM
</script>
``


I think it should be (even if you have your JS after the Form is created):我认为应该是(即使您在创建表单后拥有 JS):

window.onload = submit_document();
function submit_document(){
    document.getElementById('paypalButton').submit();
}

If you had JQuery, you may even do:如果你有 JQuery,你甚至可以这样做:

$().ready(function(){
    $("#frm1").paypalButton();
});

Would this work for you?这对你有用吗?

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

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