简体   繁体   中英

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. When I click the submit button I am redirected to paypal and everything looks right. 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. Note that some of the field values are populated with php.


<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):

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

If you had JQuery, you may even do:

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

Would this work for you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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