Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

393
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!