可以通过将表单发布到当前页面,然后使用$_POST
对象来确定下一个窗体。
在最简单的示例中,名为“page”的隐藏输入可以在每个步骤上增加其值。使用以下数据设置其他隐藏输入的值$_POST
如果在以后的步骤/表格中需要。
下面的示例方法可以做到这一点。我添加了一个短代码,[count_page_form]
可以将其包含在帖子或页面中,以便测试。所有这些都将进入theme的功能中。php
(不要在生产中使用,显然,这里没有进行消毒或验证)。
这应该是一个足够的例子,你可以修改你的工作。
示例:
add_shortcode(\'count_page_form\',\'count_page_function\');
function count_page_function(){
global $wpdb;
$current_page = $_SERVER[\'REQUEST_URI\'];
//check for $_POST value for our page_count, make it null if it isn\'t there since that means we\'re on page 1
if ($_POST && $_POST[\'page\']) {
$page_count = $_POST[\'page\'];
}
else {
$page_count = null;
}
//now let\'s start checking the page_count and displaying as needed
if ( $page_count == NULL ) {
echo \'<form method="post" action="\' . $current_page .\'">
<label for="first_name" id="first_name">First Name: </label>
<input type="text" name="first_name" id="first_name" />
<input type="hidden" value="1" name="page" />
<input type="submit" />
</form>\';
//the hidden input type above gives our $_POST[\'page\'] a value of one upon submission
}//end page 1
elseif ( $page_count == 1 ) {
//grab values from first $_POST, we will add them to hidden input below so new $_POST has them
$first_name = $_POST[\'first_name\'];
echo \'<h2>This is page two</h2>\';
// note below we add the hidden for first_name, and we change the value for page to 2
echo \'<form method="post" action="\' . $current_page .\'">
<input type="hidden" name="first_name" id="first_name" value="\'. $first_name .\'" />
<label for="second_name" id="second_name">Second Name: </label>
<input type="text" name="second_name" id="second_name" />
<input type="hidden" value="2" name="page" />
<input type="submit" />
</form>\';
}//end page 2
elseif ($page_count == 2) {
$first_name = $_POST[\'first_name\'];
$second_name = $_POST[\'second_name\'];
echo \'<h2>The third page!</h2>\';
echo $second_name;
echo $first_name;
}//end page 3
}//end count_page_function