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

394
Visualizações
HTML and PHP - How to seperate 2 forms on a single page?

I'm pretty new to HTML and currently I'm making an assignment where I have to make a HTML Form for data input and write the input to a file using PHP.

The writing to file works, but I getting the following comment on my code:

You have tested whether something has been posted, but what happens to your code if there are 2 forms on your page?

I kinda know what is being meant with this, but I am not that fluent to know how to solve this issue or where this comes from in my code.. Does this has to do with the action of the form set to $_SERVER["PHP_SELF"], the name of the submit button set wrong or anything else?

I've tried looking online for HTML forms and how to have 2 on the same page.. but I could not find anything really helpfull. If anyone can help or maybe point me to some info that explains this in detail (and with examples preferably) that would be great!

Here is just my HTML form as I have it with the PHP part checking for the submit. Rest of the code I left out as it is not relevant..

<html>
    <head>
        <title>Save and show data</title>
    </head>
    <body>
        <h2>Fill in the form below</h2>
        <form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
            <label for='name'>Naam:</label><br>
            <input type="text" id="name" name="name" placeholder = "John Doe" required><br>
            <label for='address'>Adres:</label><br>
            <input type="text" id="address" name="address" placeholder = "Sunset lane 10" required><br>
            <label for='zip'>Postcode:</label><br>
            <input type="text" id="zip" name="zip" placeholder = "15922" required><br>
            <label for='residence'>Woonplaats:</label><br>
            <input type="text" id="woonplaats" name="woonplaats" placeholder = "Somewhere" required><br>
            <label for='phone'>Telefoonnummer:</label><br>
            <input type="tel" id="phone" name="phone" placeholder = "0678945124" required><br>
            <label for='email'>E-mail:</label><br>
            <input type="email" id="email" name="email" placeholder = "johndoe@email.com" required><br><br>
            <input type="submit" name="submit_data" value="Save"><br>
        </form>
    <?php 
    if(isset($_POST["submit_data"]))
    {   
        // magic stuff happens here   
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Do you mean something like this? Each submit button has its own validation.

<?php
    if (isset($_POST['submit_data'])) {
        //first form
    }
    
    if (isset($_POST['edit_data'])) {
        //second form
    }
?>


<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
    <label for='name'>Naam:</label><br>
    <input type="text" id="name" name="name" placeholder = "John Doe" required><br>
    <input type="submit" name="submit_data" value="Save"><br>
</form>

<form method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
    <label for='name'>Naam:</label><br>
    <input type="text" id="name" name="name" placeholder = "John Doe" required><br>
    <input type="submit" name="edit_data" value="Edit"><br>
</form>
over 4 years ago · Santiago Trujillo 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