Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

395
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda