使用功能的POST

问题描述 投票:0回答:1

我有一个PHP脚本,需要根据单选按钮选择转到三个不同的URL之一,但是我必须通过POST发送变量,因为一个URL是第三方页面(未显示),我无法更改它。

我具有确定单选按钮的值并直接执行脚本的功能,但是我找不到控制从GET切换到POST的方法。

**也许有比使用我不知道的功能更好的方法?

FYI,我尝试了许多按钮选项,包括按钮而不是输入;下面显示的只是我的最新状态。

<tr> 
  <th Align=Left vAlign=top rowSpan=6> <?=$THFont?> Payment Type</font></th>
  <td> <Input Name=PayType Type=Radio Value=CK ID=Check Checked>
       <Label for=Check> Check</label></td>
</tr>
<tr>
  <td> <Input Name=PayType Type=Radio Value=CS ID=Cash>
       <Label for=Cash> Cash</label></td>
</tr>
<tr>
  <td> <Input Name=PayType Type=Radio Value=CH ID=Charge>
       <Label for=Charge> Charge to Broker AR Account</label></td>
</tr>
<tr>
  <td> &nbsp; &nbsp; <input type=text name=PayNote id=PayNote placeholder='Payment Note (for 3 payment types above)' maxlength=30 size=35></td>
</tr>
<tr>
  <td> <Input Name=PayType Type=Radio Value=CC ID=Credit>
       <Label for=Credit> Credit Card  &nbsp;<i>(Visa, Master Card, American Express, Discover)</i></label></td>
</tr>
<tr>
  <td> <Input Name=PayType Type=Radio Value=NP ID=NoPay> 
       <Label for=NoPay> Reserve Without Payment</label></td>
</tr>


<input type="button" class="buttonProcess" value="Process" onclick="processPayment('<?=$EvntCode?>','<?=$SessionID?>','<?=$MbrID?>');">


  function processPayment(EvntCode,SessionID,MbrID) {
    var PayType = $("input:radio[name='PayType']:checked").val();
    var PayNote = document.getElementById('PayNote').value;
    if (PayType == "CK" || PayType == "CS" || PayType == "CH") {
      var url = "/apps/php/PayCashStaff_Process.php?EvntCode="+EvntCode+"&SessionID="+SessionID+"&MbrID="+MbrID+"&PayType="+PayType+"&PayNote="+PayNote;
      processPay = window.location.href=url;
    }
    if (PayType == "CC") {
      var url = "/apps/php/PayCCStaff_Home.php?EvntCode="+EvntCode+"&SessionID="+SessionID+"&MbrID="+MbrID;
      processCCPay = window.location.href=url;
    }
    if (PayType == "NP") {
      var url = "/apps/php/ConfirmReservation_Process.php?EvntCode="+EvntCode+"&SessionID="+SessionID+"&MbrID="+MbrID;
      confResWindow = window.location=(url);
    }
  }
javascript php function post
1个回答
0
投票

首先构造表单,然后提交(不使用AJAX)。表单将被提交,用户将被带到目的地:

function processPayment(EvntCode, SessionID, MbrID) {
  var PayType = $("input:radio[name='PayType']:checked").val();
  var PayNote = document.getElementById('PayNote').value;
  if (PayType == "CK" || PayType == "CS" || PayType == "CH") {
    var url = "/apps/php/PayCashStaff_Process.php?EvntCode=" + EvntCode + "&SessionID=" + SessionID + "&MbrID=" + MbrID + "&PayType=" + PayType + "&PayNote=" + PayNote;
    processPay = window.location.href = url;
  }
  if (PayType == "CC") {
    var url = "/apps/php/PayCCStaff_Home.php?EvntCode=" + EvntCode + "&SessionID=" + SessionID + "&MbrID=" + MbrID;
    processCCPay = window.location.href = url;
  }
  if (PayType == "NP2") {
    var url = "/apps/php/ConfirmReservation_Process.php?EvntCode=" + EvntCode + "&SessionID=" + SessionID + "&MbrID=" + MbrID;
    confResWindow = window.location = (url);
  }

  if (PayType == "NP") {
    var f = document.createElement("form");
    f.setAttribute('method', "post");
    f.setAttribute('action', "https://postman-echo.com/post");
    f.setAttribute('id', "postform");

    var i = document.createElement("input"); //input element, hidden
    i.setAttribute('type', "hidden");
    i.setAttribute('name', "EvntCode");
    i.setAttribute('value', EvntCode);
    f.appendChild(i);

    i = document.createElement("input"); //input element, hidden
    i.setAttribute('type', "hidden");
    i.setAttribute('name', "SessionID");
    i.setAttribute('value', SessionID);
    f.appendChild(i);

    i = document.createElement("input"); //input element, hidden
    i.setAttribute('type', "hidden");
    i.setAttribute('name', "MbrID");
    i.setAttribute('value', MbrID);
    f.appendChild(i);

    document.body.appendChild(f);

    f.submit();
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
  <tr>
    <th Align=Left vAlign=top rowSpan=6>
      <?=$THFont?> Payment Type</font>
    </th>
    <td>
      <Input Name=PayType Type=Radio Value=CK ID=Check Checked>
      <Label for=Check> Check</label>
    </td>
  </tr>
  <tr>
    <td>
      <Input Name=PayType Type=Radio Value=CS ID=Cash>
      <Label for=Cash> Cash</label>
    </td>
  </tr>
  <tr>
    <td>
      <Input Name=PayType Type=Radio Value=CH ID=Charge>
      <Label for=Charge> Charge to Broker AR Account</label>
    </td>
  </tr>
  <tr>
    <td> &nbsp; &nbsp; <input type=text name=PayNote id=PayNote placeholder='Payment Note (for 3 payment types above)' maxlength=30 size=35></td>
  </tr>
  <tr>
    <td>
      <Input Name=PayType Type=Radio Value=CC ID=Credit>
      <Label for=Credit> Credit Card  &nbsp;<i>(Visa, Master Card, American Express, Discover)</i></label>
    </td>
  </tr>
  <tr>
    <td>
      <Input Name=PayType Type=Radio Value=NP ID=NoPay>
      <Label for=NoPay> Reserve Without Payment</label>
    </td>
  </tr>
</table>
<input type="button" class="buttonProcess" value="Process" onclick="processPayment('fooEvent','fooSess','fooMbr');">

注意:可以制作一个不错的表单构造函数,但您会明白。

© www.soinside.com 2019 - 2024. All rights reserved.