Как вы упомянули, вы можете сделать это на одной странице, используя значение POST из каждой формы вместе с серией операторов if / elseif, как показано ниже;
<?php
//check if the "page" value is NOT set and if true show the "page 1 form"
if(!ISSET($_POST["page"])){
//open the form tag
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
echo '<div class="formElementsWrapper formElementsUsername">
<label for="userid" class="hidden">Username</label>
<input type="text" accesskey="U" id="userid" class="formElement formElementText" name="j_username" maxlength="14" value="" placeholder="Username" autocomplete="off">
</div>
<div class="formElementsWrapper formElementsPassword">
<label for="password" class="hidden">Password</label>
<input type="password" accesskey="P" id="password" class="formElement formElementPassword" name="j_password" maxlength="32" placeholder="Password" autocomplete="off">
</div>
<div id="saveuid" class="formElementsWrapper formElementsSaveUsername">
<input type="checkbox" accesskey="S" id="saveusername" class="c29link formElement formElementCheckbox" name="saveusername" data-content-id="c29content-save-username" triggerhover="false" isclickable="true">
<label for="saveusername" class="lsc">Save username<span class="hidden">Opens a dialog</span></label>
<input type="hidden" name="save-username" id="save-username" value="false">
<input type="hidden" name="hdnuserid" id="hdnuserid">
</div>';
//now we set the "page value" by using a hidden input field
echo ' <div class="formSubmit">
<input type="hidden" name="page" value="1" />
<input type="submit" value="Sign On" name="btnSignon" id="btnSignon" class="c7" data-mrkt-tracking-id="3d6c76ba-9d34-4def-977d-a79cb8afc738">';
//always remember to close all your tags
echo '</div></form>';
}
//now we end that "if statement" with the bracket above and below create another check, for page 2
elseif($_POST["page"]==1){
//if this parameter shows as page one continue below
//start the session
session_start();
//collect the data from the first form and put it into a session values
$_SESSION["uid"] = $_POST["userid"];
//display the second form
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
<div class="formElementsWrapper formElementsUsername">
<label for="userid" class="hidden">Username</label>
<input type="text" accesskey="U" id="userid" class="formElement formElementText" name="j_username" maxlength="14" value="" placeholder="Username" autocomplete="off">
</div>
<div class="formElementsWrapper formElementsPassword">
<label for="password" class="hidden">Password</label>
<input type="password" accesskey="P" id="password" class="formElement formElementPassword" name="j_password" maxlength="32" placeholder="Password" autocomplete="off">
</div>
<div id="saveuid" class="formElementsWrapper formElementsSaveUsername">
<input type="checkbox" accesskey="S" id="saveusername" class="c29link formElement formElementCheckbox" name="saveusername" data-content-id="c29content-save-username" triggerhover="false" isclickable="true">
<label for="saveusername" class="lsc">Save username<span class="hidden">Opens a dialog</span></label>
<input type="hidden" name="save-username" id="save-username" value="false">
<input type="hidden" name="hdnuserid" id="hdnuserid">
</div>';
//again create the page number
echo ' <div class="formSubmit">
<input type="hidden" name="page" value="2" />
<input type="submit" value="Sign On" name="btnSignon" id="btnSignon" class="c7" data-mrkt-tracking-id="3d6c76ba-9d34-4def-977d-a79cb8afc738">';
//again, remember to close your tags
echo '<div></form>';
//end if statement
}
//check if page 2 is complete
elseif($_POST["page"]==2){
echo $_SESSION["uid"] . ', your form has been completed';
echo '<br><br>';
echo 'Thanks for your submission';
}
?>
В последнем утверждении elseif вы будетенужно что-то сделать со значениями, но это должно помочь вам начать работу над проектом.
Прежде чем вы начнете выпускать что-либо в Интернете, я бы настоятельно посоветовал вам ознакомиться с некоторыми основами, обязательно включите;- Защита от SQL-инъекций - Безопасное и надежное шифрование паролей - Работа с массивами
Вы НЕ ХОТИТЕ передавать пароли в заголовках сеансов, поэтому будьте осторожны при планировании
Удачи!