Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marcolino922's avatar

Replace Stripe's credit card form with inputs

I would like to know instead of using the classic Stripe form, how to unpack it in separate inputs. What should be the "name" of the respective inputs?

<div id="card-element" class="form-control"></div>

Also, need to change anything in the original javascript code?

const stripe = Stripe('{{ config('cashier.key') }}')

    const elements = stripe.elements()
    const cardElement = elements.create('card')

    cardElement.mount('#card-element')

    const form = document.getElementById('payment-form')
    const cardBtn = document.getElementById('card-button')

    form.addEventListener('submit', async (e) => {
        e.preventDefault()

        // Disable the submit button to prevent repeated clicks
        document.getElementById('card-button').disabled = true
        
        const { setupIntent, error } = await stripe.confirmCardSetup(
            cardBtn.dataset.secret, {
                payment_method: {
                    card: cardElement,
                    billing_details: {
                        name: document.getElementById('name').value
                    }
                }
            }
        )

        if(error) {
            document.getElementById('card-button').disabled = false
        } else {
            let token = document.createElement('input')
            
            token.setAttribute('type', 'hidden')
            token.setAttribute('name', 'token')
            token.setAttribute('value', setupIntent.payment_method)
            form.appendChild(token)
            form.submit();
        }
 
    })
0 likes
6 replies
jlrdw's avatar

I would advise following stripes directions, also check and see if they have other styles you can use.

martinbean's avatar

@marcolino922 You should not be capturing credit card data with your own inputs! This is not PCI-compliant and is a huge security issue if credit card data is touching your server. Just don’t do it.

Stripe gives you Elements to build your own form so that credit card data is captured in pages hosted on Stripe’s servers, meaning the data only touches their servers, and the obligation of PCI compliance is on Stripe, not you.

Marcolino922's avatar

I get it, thank you very much. If I would like to remove the various fields (card number, expiry date and security number), what can I do?

Please or to participate in this conversation.