5

Is it possible to pass custom variables in the Stripe Checkout form?

This is my form code:

<form action="/includes/api/stripe/charge.php" method="POST">
                  <script
                    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                    data-key="pk_V4y6c4urwnTkLMEVNs0qBIQQJ5Yzu"
                    data-image="/square-image.png"
                    data-name="Demo Site"
                    data-description="2 widgets ($20.00)"
                    data-amount="2000"
                    data-email="<?php echo $userdata["email"]; ?>"
                    data-userid="<?php echo $userdata["id"];?>"
                    data-currency="usd"
                    data-bitcoin="true">
                  </script>
                </form>

I have added a custom data-attribute, called data-userid although I am unable to see this field in the response.

How can I add custom value fields?

1 Answer 1

12

I found the answer to this question. Simply add an <input> field to the <form>, and get the value from that input field in your PHP page like:

$input = $_POST["inputvalue"];

So the form becomes like this:

<form action="/api/stripe/charge" method="POST">
  <script src="https://checkout.stripe.com/checkout.js" 
          class="stripe-button" 
          data-key="pk_V4y6c4urwnTkLMEVNs0qBIQQJ5Yzu" 
          data-image="/square-image.png" 
          data-name="Demo Site" 
          data-description="2 widgets ($20.00)" 
          data-amount="2000" 
          data-currency="usd" 
          data-bitcoin="true">
  </script>
  <input type="hidden" name="inputvalue" value="value">
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.