n1concepts Posted December 1, 2019 Share Posted December 1, 2019 (edited) Hi, I'm working with an example set of code to create a Stripe (Token) and that script works Great! Example code found at https://jsfiddle.net/ywain/5yz4z2yn/ However, I need to capture the 'token' which is found at line 38 within the Javascript code. My issue: how can I pass that var (result.token.id) to an external PHP file? If you want to see the simulation - just fill out the form (use 4242 4242 4242 4242 for the test card & current of future 'two-digit' year) other values are random. In the HTML code (simulated form) you'll see that the 'token' class display the token when (result.token) JS condition is met / TRUE <div class="success"> Success! Your Stripe token is <span class="token"></span> </div> I'll suppress the token from showing the var once I am able to grab the value & pass into the, external, PHP (Stripe api's for processing). Again, here's the code snippet in question from the 'Javascript file found at https://jsfiddle.net/ywain/5yz4z2yn/ if (result.token) { // Use the token to create a charge or a customer // https://stripe.com/docs/charges successElement.querySelector('.token').textContent = result.token.id; successElement.classList.add('visible'); Again, I need to (somehow) grab 'result.token.id' and (securely) pass that value to an external PHP file. Note: I do not want to use cookies b/c that not a stable solution for all browsers nor safe. Appreciate any suggestions - thx! Edited December 1, 2019 by n1concepts Quote Link to comment https://forums.phpfreaks.com/topic/309608-how-to-capture-js-value-in-var-then-pass-to-php-fiile/ Share on other sites More sharing options...
requinix Posted December 1, 2019 Share Posted December 1, 2019 Put it into a hidden input with the rest of the form that I assume you're using. 1 hour ago, n1concepts said: Note: I do not want to use cookies b/c that not a stable solution for all browsers nor safe. And you think that Javascript is? Spoiler: it isn't. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309608-how-to-capture-js-value-in-var-then-pass-to-php-fiile/#findComment-1572079 Share on other sites More sharing options...
maxxd Posted December 1, 2019 Share Posted December 1, 2019 1 hour ago, requinix said: Put it into a hidden input with the rest of the form that I assume you're using. Or use AJAX. Depends on what you're trying to accomplish and how you're trying to accomplish it. As far as the security goes, no matter what you do that part's going to be up to you, and I'd recommend not just blindly copy/pasting code from the internet in this situation. 1 Quote Link to comment https://forums.phpfreaks.com/topic/309608-how-to-capture-js-value-in-var-then-pass-to-php-fiile/#findComment-1572083 Share on other sites More sharing options...
n1concepts Posted December 6, 2019 Author Share Posted December 6, 2019 (edited) Thx for response requinix && maxxd - both your comments (I agree & on point). I would prefer to handle this on the backend with php, however, not my call - lead devs prefer JS so reason I was inquiring (thx) For the code (copying from WWW) - yeah, use to boiler plate customization (certainly not using 'as is' - thx again for respnose). We got it working but not how I would have preferred - but always multiple ways to accomplish similar results. Edited December 6, 2019 by n1concepts Quote Link to comment https://forums.phpfreaks.com/topic/309608-how-to-capture-js-value-in-var-then-pass-to-php-fiile/#findComment-1572293 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.