1

The users can pick one of the options from dropdown and pay for it (same cost for all options). The return URL in website preferences is set properly and I do get transaction info as _POST data. The assessments below is a drop-down with few options, how do I pass it paypal and get it back? I tried naming the variable as custom but that didn't work either. What am I doing wrong?

<div class="form-group">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
  <select class="form-select" id="assessments" name="assessments">
    foreach ($choices as $key => $value) {
      <option value="'.$key.'">'.$value.'</option>
    }
  </select>
  <input type="hidden" name="rm" value="2">
  <input type="hidden" name="cmd" value="_s-xclick">
  <input type="hidden" name="hosted_button_id" value="TESTBUTTONID">
  <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_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>
</div>
Srini K
  • 3,315
  • 10
  • 37
  • 47
  • I don't think so. Configured a auto return with return url where I'm processing the _POST data. I understand that this is not the most secure way of doing it, but I want to get something in place first and go from there. – Srini K Feb 01 '16 at 02:07
  • 2
    http://stackoverflow.com/questions/2847114/can-i-send-a-variable-to-paypal-and-have-it-post-it-back-to-me-when-payment-com – Niklesh Raut Feb 01 '16 at 02:23
  • https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables – StackSlave Feb 01 '16 at 03:10
  • 2
    I'm not seeing your ``. – StackSlave Feb 01 '16 at 03:23
  • This is the key, the input has to be hidden and the name of the input (not id) has to be 'custom'. – Srini K Feb 01 '16 at 16:22

2 Answers2

1

Paypal only accepts the variables mentioned in hidden. Here is the following from Paypal website:

HTML input variables in a PayPal PayPal Payments Standard FORM are always hidden from the payer's view. They have the following general format:

Please check this link: https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/formbasics/

Rafi SM
  • 28
  • 3
  • 1
    You may use a separate form to show drop down list and use the pay now button in another form. You can use Ajax to change the value of hidden input field in the pay now button form. – Rafi SM Feb 01 '16 at 02:16
1

Here is the code that worked.

<div class="form-group">
  <script type="text/javascript">
    function assessmentSelected() {
      var e = document.getElementById("assessments");
      document.getElementById("custom").value = e.options[e.selectedIndex].value;
    }
  </script>
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <select class="form-select" id="assessments" name="assessments" onchange="assessmentSelected()">
        <option value="A1">Assessment One</option>
        <option value="A2">Assessment Two</option>
        <option value="A3">Assessment Three</option>
    </select>
    <input type="hidden" id="custom" name="custom" value="A1">
    <input type="hidden" name="rm" value="2">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="TESTBUTTONID">
    <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_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>
</div>
Srini K
  • 3,315
  • 10
  • 37
  • 47