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

155
Views
Tres acciones de formularios en una página php

Supongamos que tengo una página PHP que tiene tres formularios.

  1. En el formulario uno, le pedirá al usuario que ingrese la dirección de correo electrónico mientras el código está oculto.
 <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. El formulario dos se mostrará después del paso 1. En este paso, se le pedirá al usuario que ingrese el código del paso 1 (que es igual a 42).
 <input type="number" id="code2" name="code2"> <input type="submit" value="Submit2">
  1. El formulario tres se mostrará después de ingresar el código corregido en el paso 2.
 <input type="number" id="code2" name="code2"> <input type="submit" value="Submit3">

¿Cómo puedo programarlo?

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

0

Debe indicar la acción del formulario como el nombre del archivo. Entonces, si el archivo en el que está trabajando se llama example.php , debería verse así:

 $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

Podrías probar este enfoque:

 <?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!