我使用以下代码创建了一个两步表单:
<form class="form" method="POST" action="<?php bloginfo('url'); ?>/contact-us/">
<? if (!$_POST['step']) { ?>
<h1>Step 1 of 2</h1><br />
<input type="hidden" name="step" value="1" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="title" id="title" value="Title*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">Continue</button>
<? } else if ($_POST['step'] == 1) {
foreach($_POST as $name => $value) {
if ($name <> "step") { echo "<input type=\"hidden\" name=\"$name\" value=\"$value\" />"; }
} ?>
<h1>Step 2 of 2</h1><br />
<input type="hidden" name="step" value="2" />
<table border="0" width="100%">
<tr>
<td>
<input type="text" name="name" id="name" value="Name*" />
</td>
</tr>
</table>
<button class="continue-button" type="submit" name="submit">submit</button>
<? } else if ($_POST['step'] == 2) { //do stuff
echo "Do stuff here";
} ?>
</form>
如何在第 2 步中添加后退按钮?将添加几个步骤,而不仅仅是 2 个,因此用户需要能够在这些步骤中前进和后退,同时保留他们填写的内容。