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

147
Views
Three forms actions in one php page

Assume that I have a PHP page that has three forms.

  1. Form one, it will ask the user to enter the email address while the code is hidden.
<label for="email">Email Address:</label> <input type="text" id="email" name="email">
<input type="hidden" id="code" name="code" value="42"> <input type="submit" value="Submit1">
  1. Form two will be showing after step 1. In this step, the user will be asked to enter the code in step 1 (which is equal to 42).
<input type="number" id="code2" name="code2"> <input type="submit" value="Submit2">
  1. Form three, will be showing after entering corrected code in step 2.
<input type="number" id="code2" name="code2"> <input type="submit" value="Submit3">

How can I program it?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to state the action of the form as the name of the file. So, if the file you are working on is name example.php it should look like so:

$email = trim(get_variable_value('email'));
$code = trim(get_variable_value('code'));
$code2 = trim(get_variable_value('code2'));

//make sure to validate the input!! if it's not valid send back

<? if(!isset($email)){ //alternatively, you can add a hidden input `stage`. I just don't like it, as it can be bypassed.
?>
    <form name="transferToNewForm" action="example.php" method="post">
        <label for="email">Email Address:</label> <input type="text" id="email" name="email">
        <input type="hidden" id="code" name="code" value="42">
        <input type="submit" value="Submit1">
    </form>
<? } 
if(isset($email) && isset($code) && $code == 42){ ?>
    <form name="transferToNewerForm" action="example.php" method="post">
        <label for="email">Email Address:</label> <input type="text" id="email" name="email" value="<?= $email ?>" readonly>
        <input type="number" id="code2" name="code2">
        <input type="submit" value="Submit2">
    </form>
<? } 
if(isset($email) && isset($code2) && $code2 == 42){ ?>
    <form name="finalFrom" action="theActualPageYouWant.php" method="post">
        <label for="email">Email Address:</label> <input type="text" id="email" name="email" value="<?= $email ?>" readonly>
        <input type="number" id="code2" name="code2">
        <input type="submit" value="Submit3">
    </form>
<? } ?>
about 4 years ago · Juan Pablo Isaza Report

0

You could try this approach :

<?php 
function getFormContent() {
  $email = $_POST['email'] ?? null; //$email equals to null if it is undefined, to prevent errors

  if (!$email) {
    echo '<input type="text" name="email" placeholder="Email.." />';
    echo '<input type="hidden" id="code" name="code" value="42">';
  } else {
    echo '<input type="hidden" name="email" value="'.$email.'" />'; //keep email set after submitting first step
  }

  if ($email && $_POST['code']) {
    if (isset($_POST['code2']) && $_POST['code2'] == $_POST['code']) {
      //final form
    } 
    else { //second step
      echo '<input type="number" id="code2" name="code2">';
      echo '<input type="hidden" id="code" name="code" value="42">'; //we still need this in case user submitted a wrong code
    }
  }
}
?>

<form method="post">
  <?= getFormContent() ?>
  <input type="submit" />
</form>
about 4 years ago · Juan Pablo Isaza 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!