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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page