You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PayPal支付表单参数传递异常问题排查

Fixing PayPal Payment Form Issues: Item Name and Amount Not Passing Through

Hey there, let's break down why your PayPal form isn't passing the sessionType (item description) and grandTotal (amount) values, and fix those issues step by step:

Key Problems Identified

  • Disabled form elements don't get submitted: All your visible input/textarea fields are set to disabled="disabled". Browsers exclude disabled elements from form submission, so PayPal never receives the item_name (sessionType) and amount (grandTotal) values you're trying to send.
  • Minor syntax error: The sessionDays textarea has an unclosed id attribute (missing a quote), which could cause unexpected behavior in some browsers.
  • Redundant visible fields for required PayPal params: You're using visible disabled inputs to display values, but you need to ensure critical PayPal parameters are sent either as hidden fields or adjust the visible fields so their values are submitted.

Step-by-Step Fixes

1. Use Read-Only for Visible Fields, Add Hidden Params for PayPal

Instead of disabling visible fields (which blocks submission), set them to readonly="readonly" (so users can't edit but can view values) and add hidden input fields for PayPal-specific parameters like item_name and amount—these hidden fields will be sent to PayPal during submission.

2. Fix the Textarea Syntax Error

Close the id attribute for the sessionDays textarea properly to avoid browser parsing issues.

3. Verify PayPal Parameter Names

Double-check that you're using PayPal's exact, case-sensitive parameter names (e.g., item_name for item description, amount for total cost).

Here's the corrected form code:

<form style="padding: 20px; border: 2px solid #f00; background: #fff; box-shadow: 10px 10px 20px -5px #000; border-radius: 10px; font-size:15px;" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
  <div class="form-row">
    <div class="form-group col-md-12 mx-auto text-center">
      <h3 class="text-uppercase">Please Confirm Your Payment</h3>
    </div>
  </div>
  <!-- Core PayPal Hidden Parameters -->
  <input type="hidden" name="cmd" value="_xclick">
  <input type="hidden" name="business" value="paypaltestgmail.com">
  <input type="hidden" name="quantity" value="1">
  <input type="hidden" name="item_name" value="<?php echo $sessionType; ?>">
  <input type="hidden" name="amount" value="<?php echo $grandTotal; ?>">
  <input type="hidden" name="no_shipping" value="1">
  <input type="hidden" name="no_note" value="1">
  <input type="hidden" name="currency_code" value="USD">
  <input type="hidden" name="return" value="http://www.example.net/payment-success/">

  <!-- Visible Read-Only Fields (for user confirmation) -->
  <div class="form-row">
    <div class="form-group col-md-4">
      <label for="fullName">Full Name</label>
      <input type="text" class="form-control" id="fullName" value="<?php echo $firstName . ' ' . $lastName; ?>" name="fullName" readonly="readonly">
    </div>
    <div class="form-group col-md-4">
      <label for="email">Email</label>
      <input type="text" class="form-control" id="email" value="<?php echo $email; ?>" name="email" readonly="readonly">
    </div>
    <div class="form-group col-md-4">
      <label for="age">Age</label>
      <input type="text" class="form-control" id="age" value="<?php echo $age; ?>" name="age" readonly="readonly">
    </div>
  </div>
  <div class="form-row">
    <div class="form-group col-md-4">
      <label for="sessionType">Session Type</label>
      <input type="text" class="form-control" id="sessionType" value="<?php echo $sessionType; ?>" readonly="readonly">
    </div>
    <div class="form-group col-md-4">
      <label for="sessionDays">Session Days</label>
      <textarea class="form-control" id="sessionDays" name="sessionDays" readonly="readonly"><?php echo $sessionDays; ?></textarea>
    </div>
    <div class="form-group col-md-4">
      <label for="sessionTime">Session Time</label>
      <textarea class="form-control" id="sessionTime" name="sessionTime" readonly="readonly"><?php echo implode(', ', $_POST['sessionTime']); ?></textarea>
    </div>
  </div>
  <div class="form-row">
    <div class="form-group col-md-4">
      <label for="totalCost">Total Cost</label>
      <input type="text" class="form-control" id="totalCost" value="<?php echo $totalCost; ?>" name="totalCost" readonly="readonly">
    </div>
    <div class="form-group col-md-4">
      <label for="totalTax">Tax Amount</label>
      <input type="text" class="form-control" id="totalTax" value="<?php echo $totalTax; ?>" name="totalTax" readonly="readonly">
    </div>
    <div class="form-group col-md-4">
      <label for="grandTotal">Grand Total</label>
      <input type="text" class="form-control" id="grandTotal" value="<?php echo $grandTotal; ?>" readonly="readonly">
    </div>
  </div>
  <button type="submit" class="btn btn-primary btn-lg d-block mx-auto text-uppercase">Confirm & Pay</button>
</form>

Additional Tips

  • Readonly vs Disabled: readonly preserves field values during submission while preventing edits, whereas disabled blocks both edits and submission—this was your core issue.
  • Testing: Use PayPal's sandbox environment for testing to avoid real transactions during development.
  • Parameter Validation: Always sanitize and validate PHP variables like $sessionType and $grandTotal before outputting them to the form to prevent XSS vulnerabilities.

内容的提问来源于stack exchange,提问作者Milan Bastola

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:03:02