Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Retrieve data from HTML form to server file

I am working on the Stripe payment API and I have a form to collect data that is written in HTML and would like to retrieve the collected data to another javascript file (server.js). I have tried changing the ${AMOUNT} to req.body.amount but seems that is not the case. Is it actually possible to retrieve the data via the form method? Or it is only be done in the fetch method?

HTML:

<form action="/create-checkout-session" method="POST" id="create-checkout-session">
  <div className="description">
    <span>Price:</span> 
    <input type="number" className="field" id="amount" name="amount" min="500"/>
    <button type="submit" id="checkout">
      Checkout
    </button>
  </div>
</form>

Javascript (server.js):

app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
line_items: [
  {
    price_data: {
      currency: 'hkd',
      product_data: {
        name: "Test",
      },
      unit_amount: ${AMOUNT},
    },
    quantity: 1,
  },
],
mode: 'payment',
success_url: `${YOUR_DOMAIN}?success=true`,
cancel_url: `${YOUR_DOMAIN}?canceled=true`,});
res.redirect(303, session.url);
});
app.listen(4242, () => console.log('Running on port 4242'));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have solved this by adding express.urlencoded in the server.js, which looks like this:

app.use(express.urlencoded({ extended: true }));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda