How to add custom fields to popup form of Stripe Checkout

后端 未结 3 1517
长发绾君心
长发绾君心 2021-02-18 23:32

How can i add custom fields to Stripe Checkout form such as First Name, Last Name and maybe even a checkbox with a custom button? So far i\'ve come up with this;



        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-19 00:33

    Stripe now recommends using the stripe.js method versus the deprecated checkout modal method (not to be confused with the new Stripe Checkout).

    To that end, in order to add custom fields (such as name, package type, custom tags, etc), what I found works is tweaking the stripe.js function stripeTokenHandler() by adding:

    var customInput = document.createElement('input');
    customInput.setAttribute('type', 'hidden');
    customInput.setAttribute('name', 'customInput');
    customInput.setAttribute('value', $("input[name=customInput]:checked").val());
    form.appendChild(customInput);
    

    So if I had a radio button group called "customInput", it would attach the value of whatever radio button was selected to the "customInput" $_POST field. This way the target script can retrieve it and use it.

    Hope this helps someone.

提交回复
热议问题