Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多步骤表单如何在不同页面之间使用信息_Php_Forms - Fatal编程技术网

Php 多步骤表单如何在不同页面之间使用信息

Php 多步骤表单如何在不同页面之间使用信息,php,forms,Php,Forms,我尝试在php中使用多集表单,因为我不知道jquery和javascript(理解它有困难) 首先,我想做的是: 第1页: Q1您要多少号码? 例如,用户输入“2” 第2页: Q2您想要的每个数字有多少个字母: (看起来像:1号:---2号:-) 例如,用户输入“2”作为第一个,输入“1”作为第二个 第3页: (看起来像:) 数字1:字母1:---字母2:---- 数字2:字母1:--- 到目前为止,在第1页和第2页之间一切正常,但在第2页和第3页之间什么也没有发生 另一个问题是,如果用户在3和

我尝试在php中使用多集表单,因为我不知道jquery和javascript(理解它有困难)

首先,我想做的是:

第1页:

Q1您要多少号码? 例如,用户输入“2”

第2页:

Q2您想要的每个数字有多少个字母:

(看起来像:1号:---2号:-)

例如,用户输入“2”作为第一个,输入“1”作为第二个

第3页:

(看起来像:)

数字1:字母1:---字母2:----

数字2:字母1:---

到目前为止,在第1页和第2页之间一切正常,但在第2页和第3页之间什么也没有发生 另一个问题是,如果用户在3和2之间“返回”,则第2页将一无所获,因为第一页的值“丢失”

我搜索了很长时间,没有找到任何东西,如果你有任何建议,我会很高兴

这是我的密码:

   <?php
   if ( isset( $_POST["step"] ) and $_POST["step"] >= 1 and $_POST["step"]<= 4 ) {
call_user_func( "processStep" . (int)$_POST["step"] );
   } else {
displayStep1();
    }
    function processStep1() {
displayStep2();
    }
   function processStep2() {
if ( isset( $_POST["submitButton"] ) and $_POST["submitButton"] =="< Back" ) {
    displayStep1();
} else {
    displayStep3();
}
    }
   function processStep3() {
if ( isset( $_POST["submitButton"] ) and $_POST["submitButton"] =="< Back" ) {
    displayStep2();
} else {
    displayThanks();
}
     }
    function displayStep1() {
    ?>
<h1>Step 1</h1>

<form action="" method="post">

<input type="hidden" name="step" value="1" />
<input type="hidden" name="number2" value="" />

<label for="number">Combien de chiffres?</label>
<input type="text" name="number" id="number" value=" " />

<div style="clear: both;">
<input type="submit" name="submitButton" id="nextButton" value="Next" />

</form>

<?php
}
function displayStep2() {
?>

<h1>Step 2</h1>
<form action="" method="post">

<input type="hidden" name="step" value="2" />
<input type="hidden" name="number" value="" />
<label for="number2">Combien de lettre pour chaque chiffres?</label>

<?php 
$num = $_POST['number'];
    for ($i = 1; $i <= $num; $i++) {
        echo "Numero ";
        echo $i;
?>  

<input type="text" name="number2" id="number2"/>

<?php
}
?>

<div style="clear: both;">
<input type="submit" name="submitButton" id="nextButton" value="Next &gt;" />
<input type="submit" name="submitButton" id="backButton" value="&lt; Back" />
</form>

<?php
}
function displayStep3() {
?>

<h1>Step 3</h1>
<form action="" method="post">

<input type="hidden" name="step" value="3" />
<input type="hidden" name="number" value="" />
<input type="hidden" name="number2" value="" />
<label for="number3">Choisir lettres</label>

<?php 
$num = $_POST['number'];
    for ($i = 1; $i <= $num; $i++) {
        echo "Numero ";
        echo $i;

    $num2 = $_POST['number2'];
        for ($j = 1; $j <= $num2; $j++) {
            echo "Lettre ";
            echo $j;
?>  

<input type="text" name="number3" id="number3"/>

<?php
}
}
?>

<div style="clear: both;">
<input type="submit" name="submitButton" id="nextButton" value="Next &gt;" />
<input type="submit" name="submitButton" id="backButton" value="&lt; Back" />
</form>

<?php
}
function displayThanks() {
?>

<h1>Merci</h1>

<?php
}
?>

第一步
奇夫雷斯酒店?
步骤2
你想喝点什么?
步骤3
乐团
谢谢

使用session可获得每页的数据。您有2个选项。1) 通过
I put this:session_start()提交每个步骤的值$_会话['number']=$_POST['number'];在我的第一个表单之后,但我得到一个错误:未定义索引:number