node.js server
app.post('/create-checkout-session', (req,res) =>{
console.log(req.form);
console.log(req.body);
const session = await stripe.checkout.sessions.create({
line_items: [
{
price: "price_id",
quantity: 1,
},
],
metadata: {
id: 1,
email: "soubhagya",
},
mode: "payment",
success_url: `https://www.youtube.com/?success=true`,
cancel_url: `https://www.youtube.com/?canceled=true`,
});
res.redirect(303, session.url);
})
React frontend
<form
action="http://localhost:4000/create-checkout-session"
method="POST"
>
<input
type="text"
name="user"
value={"hellowowowowowo"}
disabled
/>
<button
type="submit"
className="w-32 text-white bg-primary-purple hover:bg-primary-700 font-medium rounded-sm text-sm p-4 xs:w-full"
>
GET STARTED
</button>
</form>
Here is my code where i am sending some data to baackend. but,In backend i am not getting any data.
How can i receive form data in backend ?
Please take a loook
2
Answers
I think you defined routes.js or something file as a pre-url.
Please make sure.
Your backend looks fine, but instead of using forms actions to send request, why not use the onSubmit event. It should look something like that:
I used the fetch method in my example, but you can use any library that you want (Axios for example).