Stripe JS card element won't allow user input in FlaskHTML text input allow only numeric inputHow to partially validate form fields prior to stripe card validation that's in the same formHow to allow users to enter custom amount vs charging set amount in stripe?Stripe - Cannot charge a customer that has no active cardSave card details while doing stripe paymentStripe: card holder name verificationStripe Elements forcing a postal codeStripe python attach existing card/source to new customerHow to POST stripe custom checkout token to flask backendStripe connect share card source not working

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

How do I draw and define two right triangles next to each other?

Do I have a twin with permutated remainders?

How is it possible to have an ability score that is less than 3?

Languages that we cannot (dis)prove to be Context-Free

Perform and show arithmetic with LuaLaTeX

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function

Is it possible to run Internet Explorer on OS X El Capitan?

Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)

Character reincarnated...as a snail

What's the output of a record needle playing an out-of-speed record

RSA: Danger of using p to create q

How old can references or sources in a thesis be?

Intersection point of 2 lines defined by 2 points each

Are the number of citations and number of published articles the most important criteria for a tenure promotion?

How to determine what difficulty is right for the game?

dbcc cleantable batch size explanation

What typically incentivizes a professor to change jobs to a lower ranking university?

Modeling an IP Address

I'm flying to France today and my passport expires in less than 2 months

Why is consensus so controversial in Britain?

Can I make popcorn with any corn?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?



Stripe JS card element won't allow user input in Flask


HTML text input allow only numeric inputHow to partially validate form fields prior to stripe card validation that's in the same formHow to allow users to enter custom amount vs charging set amount in stripe?Stripe - Cannot charge a customer that has no active cardSave card details while doing stripe paymentStripe: card holder name verificationStripe Elements forcing a postal codeStripe python attach existing card/source to new customerHow to POST stripe custom checkout token to flask backendStripe connect share card source not working






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.



Here is my code for the views function:



@billing.route('/charge', methods=['GET', 'POST'])
def charge():
if request.method == 'POST':
customer = stripe.Customer.create(
email='customer@example.com',
source=request.form['stripeToken']
)

charge = stripe.Charge.create(
customer=customer.id,
amount=request.form['amountInCents'],
currency='usd',
description='Flask Charge'
)
return render_template('billing/charge.html')


After looking at the web console I'm receiving this error:



Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
Make sure the element exists on the page before calling mount().



How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1










share|improve this question




























    0















    I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.



    Here is my code for the views function:



    @billing.route('/charge', methods=['GET', 'POST'])
    def charge():
    if request.method == 'POST':
    customer = stripe.Customer.create(
    email='customer@example.com',
    source=request.form['stripeToken']
    )

    charge = stripe.Charge.create(
    customer=customer.id,
    amount=request.form['amountInCents'],
    currency='usd',
    description='Flask Charge'
    )
    return render_template('billing/charge.html')


    After looking at the web console I'm receiving this error:



    Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
    Make sure the element exists on the page before calling mount().



    How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1










    share|improve this question
























      0












      0








      0








      I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.



      Here is my code for the views function:



      @billing.route('/charge', methods=['GET', 'POST'])
      def charge():
      if request.method == 'POST':
      customer = stripe.Customer.create(
      email='customer@example.com',
      source=request.form['stripeToken']
      )

      charge = stripe.Charge.create(
      customer=customer.id,
      amount=request.form['amountInCents'],
      currency='usd',
      description='Flask Charge'
      )
      return render_template('billing/charge.html')


      After looking at the web console I'm receiving this error:



      Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
      Make sure the element exists on the page before calling mount().



      How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1










      share|improve this question














      I have used Stripe's Element example 1, found here: https://jsfiddle.net/ywain/2qyamjga/ to test Stripe Elements with Flask. In my app, the name and phone number fields allow user input but the card field does not.



      Here is my code for the views function:



      @billing.route('/charge', methods=['GET', 'POST'])
      def charge():
      if request.method == 'POST':
      customer = stripe.Customer.create(
      email='customer@example.com',
      source=request.form['stripeToken']
      )

      charge = stripe.Charge.create(
      customer=customer.id,
      amount=request.form['amountInCents'],
      currency='usd',
      description='Flask Charge'
      )
      return render_template('billing/charge.html')


      After looking at the web console I'm receiving this error:



      Error: The selector you specified (#card-element) applies to no DOM elements that are currently on the page.
      Make sure the element exists on the page before calling mount().



      How would I go about doing this? Any suggestions would be greatly appreciated. The stripe source code can be found here: https://github.com/stripe/elements-examples/#example-1







      javascript stripe-payments






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 at 1:19









      polymathpolymath

      688




      688






















          1 Answer
          1






          active

          oldest

          votes


















          0














          After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:



          <script src="https://js.stripe.com/v3/"></script>
          <body>
          <form>
          <div class="group">
          <label>
          <span>Name</span>
          <input name="cardholder-name" class="field" placeholder="Jane Doe" />
          </label>
          <label>
          <span>Phone</span>
          <input class="field" placeholder="(123) 456-7890" type="tel" />
          </label>
          </div>
          <div class="group">
          <label>
          <span>Card</span>
          <div id="card-element" class="field"></div>
          </label>
          </div>
          <button type="submit">Pay $25</button>
          <div class="outcome">
          <div class="error"></div>
          <div class="success">
          Success! Your Stripe token is <span class="token"></span>
          </div>
          </div>
          </form>
          </body>

          <script>
          var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
          var elements = stripe.elements();

          // Custom styling can be passed to options when creating an Element.
          var style =
          base:
          // Add your base input styles here. For example:
          fontSize: '16px',
          color: "#32325d",

          ;

          var card = elements.create('card',
          style:
          base:
          iconColor: '#666EE8',
          color: '#31325F',
          lineHeight: '40px',
          fontWeight: 300,
          fontFamily: 'Helvetica Neue',
          fontSize: '15px',

          '::placeholder':
          color: '#CFD7E0',
          ,
          ,

          );
          card.mount('#card-element');

          function setOutcome(result)
          var successElement = document.querySelector('.success');
          var errorElement = document.querySelector('.error');
          successElement.classList.remove('visible');
          errorElement.classList.remove('visible');

          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');
          else if (result.error)
          errorElement.textContent = result.error.message;
          errorElement.classList.add('visible');



          card.on('change', function(event)
          setOutcome(event);
          );

          document.querySelector('form').addEventListener('submit', function(e)
          e.preventDefault();
          var form = document.querySelector('form');
          var extraDetails =
          name: form.querySelector('input[name=cardholder-name]').value,
          ;
          stripe.createToken(card, extraDetails).then(setOutcome);
          );

          </script>





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073069%2fstripe-js-card-element-wont-allow-user-input-in-flask%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:



            <script src="https://js.stripe.com/v3/"></script>
            <body>
            <form>
            <div class="group">
            <label>
            <span>Name</span>
            <input name="cardholder-name" class="field" placeholder="Jane Doe" />
            </label>
            <label>
            <span>Phone</span>
            <input class="field" placeholder="(123) 456-7890" type="tel" />
            </label>
            </div>
            <div class="group">
            <label>
            <span>Card</span>
            <div id="card-element" class="field"></div>
            </label>
            </div>
            <button type="submit">Pay $25</button>
            <div class="outcome">
            <div class="error"></div>
            <div class="success">
            Success! Your Stripe token is <span class="token"></span>
            </div>
            </div>
            </form>
            </body>

            <script>
            var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
            var elements = stripe.elements();

            // Custom styling can be passed to options when creating an Element.
            var style =
            base:
            // Add your base input styles here. For example:
            fontSize: '16px',
            color: "#32325d",

            ;

            var card = elements.create('card',
            style:
            base:
            iconColor: '#666EE8',
            color: '#31325F',
            lineHeight: '40px',
            fontWeight: 300,
            fontFamily: 'Helvetica Neue',
            fontSize: '15px',

            '::placeholder':
            color: '#CFD7E0',
            ,
            ,

            );
            card.mount('#card-element');

            function setOutcome(result)
            var successElement = document.querySelector('.success');
            var errorElement = document.querySelector('.error');
            successElement.classList.remove('visible');
            errorElement.classList.remove('visible');

            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');
            else if (result.error)
            errorElement.textContent = result.error.message;
            errorElement.classList.add('visible');



            card.on('change', function(event)
            setOutcome(event);
            );

            document.querySelector('form').addEventListener('submit', function(e)
            e.preventDefault();
            var form = document.querySelector('form');
            var extraDetails =
            name: form.querySelector('input[name=cardholder-name]').value,
            ;
            stripe.createToken(card, extraDetails).then(setOutcome);
            );

            </script>





            share|improve this answer



























              0














              After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:



              <script src="https://js.stripe.com/v3/"></script>
              <body>
              <form>
              <div class="group">
              <label>
              <span>Name</span>
              <input name="cardholder-name" class="field" placeholder="Jane Doe" />
              </label>
              <label>
              <span>Phone</span>
              <input class="field" placeholder="(123) 456-7890" type="tel" />
              </label>
              </div>
              <div class="group">
              <label>
              <span>Card</span>
              <div id="card-element" class="field"></div>
              </label>
              </div>
              <button type="submit">Pay $25</button>
              <div class="outcome">
              <div class="error"></div>
              <div class="success">
              Success! Your Stripe token is <span class="token"></span>
              </div>
              </div>
              </form>
              </body>

              <script>
              var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
              var elements = stripe.elements();

              // Custom styling can be passed to options when creating an Element.
              var style =
              base:
              // Add your base input styles here. For example:
              fontSize: '16px',
              color: "#32325d",

              ;

              var card = elements.create('card',
              style:
              base:
              iconColor: '#666EE8',
              color: '#31325F',
              lineHeight: '40px',
              fontWeight: 300,
              fontFamily: 'Helvetica Neue',
              fontSize: '15px',

              '::placeholder':
              color: '#CFD7E0',
              ,
              ,

              );
              card.mount('#card-element');

              function setOutcome(result)
              var successElement = document.querySelector('.success');
              var errorElement = document.querySelector('.error');
              successElement.classList.remove('visible');
              errorElement.classList.remove('visible');

              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');
              else if (result.error)
              errorElement.textContent = result.error.message;
              errorElement.classList.add('visible');



              card.on('change', function(event)
              setOutcome(event);
              );

              document.querySelector('form').addEventListener('submit', function(e)
              e.preventDefault();
              var form = document.querySelector('form');
              var extraDetails =
              name: form.querySelector('input[name=cardholder-name]').value,
              ;
              stripe.createToken(card, extraDetails).then(setOutcome);
              );

              </script>





              share|improve this answer

























                0












                0








                0







                After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:



                <script src="https://js.stripe.com/v3/"></script>
                <body>
                <form>
                <div class="group">
                <label>
                <span>Name</span>
                <input name="cardholder-name" class="field" placeholder="Jane Doe" />
                </label>
                <label>
                <span>Phone</span>
                <input class="field" placeholder="(123) 456-7890" type="tel" />
                </label>
                </div>
                <div class="group">
                <label>
                <span>Card</span>
                <div id="card-element" class="field"></div>
                </label>
                </div>
                <button type="submit">Pay $25</button>
                <div class="outcome">
                <div class="error"></div>
                <div class="success">
                Success! Your Stripe token is <span class="token"></span>
                </div>
                </div>
                </form>
                </body>

                <script>
                var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
                var elements = stripe.elements();

                // Custom styling can be passed to options when creating an Element.
                var style =
                base:
                // Add your base input styles here. For example:
                fontSize: '16px',
                color: "#32325d",

                ;

                var card = elements.create('card',
                style:
                base:
                iconColor: '#666EE8',
                color: '#31325F',
                lineHeight: '40px',
                fontWeight: 300,
                fontFamily: 'Helvetica Neue',
                fontSize: '15px',

                '::placeholder':
                color: '#CFD7E0',
                ,
                ,

                );
                card.mount('#card-element');

                function setOutcome(result)
                var successElement = document.querySelector('.success');
                var errorElement = document.querySelector('.error');
                successElement.classList.remove('visible');
                errorElement.classList.remove('visible');

                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');
                else if (result.error)
                errorElement.textContent = result.error.message;
                errorElement.classList.add('visible');



                card.on('change', function(event)
                setOutcome(event);
                );

                document.querySelector('form').addEventListener('submit', function(e)
                e.preventDefault();
                var form = document.querySelector('form');
                var extraDetails =
                name: form.querySelector('input[name=cardholder-name]').value,
                ;
                stripe.createToken(card, extraDetails).then(setOutcome);
                );

                </script>





                share|improve this answer













                After debugging I discovered the error was because my Javascript was before the html. The Javascript should be placed below the html for the form fields to work correctly:



                <script src="https://js.stripe.com/v3/"></script>
                <body>
                <form>
                <div class="group">
                <label>
                <span>Name</span>
                <input name="cardholder-name" class="field" placeholder="Jane Doe" />
                </label>
                <label>
                <span>Phone</span>
                <input class="field" placeholder="(123) 456-7890" type="tel" />
                </label>
                </div>
                <div class="group">
                <label>
                <span>Card</span>
                <div id="card-element" class="field"></div>
                </label>
                </div>
                <button type="submit">Pay $25</button>
                <div class="outcome">
                <div class="error"></div>
                <div class="success">
                Success! Your Stripe token is <span class="token"></span>
                </div>
                </div>
                </form>
                </body>

                <script>
                var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXX');
                var elements = stripe.elements();

                // Custom styling can be passed to options when creating an Element.
                var style =
                base:
                // Add your base input styles here. For example:
                fontSize: '16px',
                color: "#32325d",

                ;

                var card = elements.create('card',
                style:
                base:
                iconColor: '#666EE8',
                color: '#31325F',
                lineHeight: '40px',
                fontWeight: 300,
                fontFamily: 'Helvetica Neue',
                fontSize: '15px',

                '::placeholder':
                color: '#CFD7E0',
                ,
                ,

                );
                card.mount('#card-element');

                function setOutcome(result)
                var successElement = document.querySelector('.success');
                var errorElement = document.querySelector('.error');
                successElement.classList.remove('visible');
                errorElement.classList.remove('visible');

                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');
                else if (result.error)
                errorElement.textContent = result.error.message;
                errorElement.classList.add('visible');



                card.on('change', function(event)
                setOutcome(event);
                );

                document.querySelector('form').addEventListener('submit', function(e)
                e.preventDefault();
                var form = document.querySelector('form');
                var extraDetails =
                name: form.querySelector('input[name=cardholder-name]').value,
                ;
                stripe.createToken(card, extraDetails).then(setOutcome);
                );

                </script>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 9 at 1:19









                polymathpolymath

                688




                688





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073069%2fstripe-js-card-element-wont-allow-user-input-in-flask%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme