dream890110 2017-01-12 21:56
浏览 30
已采纳

将SESSION数据存储在单个表单中[关闭]

I am trying to store data in $_SESSION variables so I can use it in other parts of the form.

I have an input for team name which I need to use within a drop down a couple of steps down the form, the team name come from the user input only.

Im struggling to pass this data throughout the form and then post it at the end.

The session is being set in header.php

<?php
if(!empty($_POST)) {
    $_SESSION['dashboardName'] = $_POST['dashboardName'];
    $_SESSION['teamName'] = $_POST['teamName'];
    $_SESSION['firstName'] = $_POST['firstName']; 
    $_SESSION['lastName'] = $_POST['lastName'];      
    $_SESSION['memberTeam'] = $_POST['memberTeam']; 
    $_SESSION['stenData'] = $_POST['stenData'];
    $_SESSION['score_1'] = $_POST['score_1'];
    $_SESSION['score_2'] = $_POST['score_2']; 
    $_SESSION['score_3'] = $_POST['score_3']; 
    $_SESSION['score_4'] = $_POST['score_4'];  
    $_SESSION['score_5'] = $_POST['score_5']; 
    $_SESSION['score_6'] = $_POST['score_6']; 
    $_SESSION['score_7'] = $_POST['score_7']; 
    $_SESSION['score_8'] = $_POST['score_8'];                                           
}
?>

<form action="" method="POST">

<!-- STEP :: 1 -->
    <div class="step-one">
    <h1>STEP 1</h1>
        <input type="text" name="dashboardName" required placeholder="Dashboard Name" value="<?php echo $_SESSION['dashboardName']; ?>">
        <button class="step-one-next">Next</button>
    </div>

<!-- STEP :: 2 -->
    <div class="step-two">
    <h1>STEP 2</h1>
        <input type="text" name="teamName" placeholder="Team name" required value="<?php echo $_SESSION['teamName']; ?>">
        <button class="step-two-previous">Previous</button>   
        <button class="step-two-next">Next</button>        
    </div>

<!-- STEP :: 3 -->
    <div class="step-three">
    <h1>STEP 3</h1>
        <input type="text" name="firstName" placeholder="First Name" required value="<?php echo $_SESSION['firstName']; ?>">
        <input type="text" name="lastName" placeholder="Last Name" required value="<?php echo $_SESSION['lastName']; ?>">
        <button class="step-three-previous">Previous</button>
        <button class="step-three-next">Next</button>
    </div>

<!-- STEP :: 4 -->    
    <div class="step-four">
    <h1>STEP 4</h1>
        <select name="memberTeam">
            <option><?php echo $_SESSION['teamName']; ?></option>
        </select>
        <button class="step-four-previous">Previous</button>
        <button class="step-four-next">Next</button>        
    </div>

<!-- STEP :: 5 -->     
    <div class="step-five">
    <h1>STEP 5</h1>
        <textarea name="stenData" placeholder="Paste Sten Data..." required><?php echo $_SESSION['stenData']; ?></textarea>
        <button class="step-five-previous">Previous</button>
        <button class="step-five-next">Next</button>        
    </div>

<!-- STEP :: 6 -->   
    <div class="step-six">  
    <h1>STEP 6</h1>
        <select name="score_1">
            <option selected="selected"><?php echo $_SESSION['score_1']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select>  

        <select name="score_2">
            <option selected="selected"><?php echo $_SESSION['score_2']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select>  

        <select name="score_3">
            <option selected="selected"><?php echo $_SESSION['score_3']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 

        <select name="score_4">
            <option selected="selected"><?php echo $_SESSION['score_4']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 

         <select name="score_5">
            <option selected="selected"><?php echo $_SESSION['score_5']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 

        <select name="score_6">
            <option selected="selected"><?php echo $_SESSION['score_6']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 

         <select name="score_7">
            <option selected="selected"><?php echo $_SESSION['score_7']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 

        <select name="score_8">
            <option selected="selected"><?php echo $_SESSION['score_8']; ?></option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
        </select> 
        <button class="step-six-previous">Previous</button>
        <button class="step-six-next">Next</button>                           
    </div>




<!-- STEP :: 7 -->
    <div class="step-seven">   
    <h1>STEP 7</h1> 
    <p><?php echo $_SESSION['dashboardName']; ?></p>
        <button class="step-seven-previous">Previous</button>
        <input type="submit" name="test" value="Submit">
    </div>

</form>

<script>
$(".step-one-next").click(function(){
    $(".step-one").hide();
    $(".step-two").show();
});
$(".step-two-previous").click(function(){
    $(".step-two").hide();
    $(".step-one").show();
});
$(".step-two-next").click(function(){
    $(".step-two").hide();
    $(".step-three").show();
});
$(".step-three-previous").click(function(){
    $(".step-three").hide();
    $(".step-two").show();
});
$(".step-three-next").click(function(){
    $(".step-three").hide();
    $(".step-four").show();
});
$(".step-four-previous").click(function(){
    $(".step-four").hide();
    $(".step-three").show();
});
$(".step-four-next").click(function(){
    $(".step-four").hide();
    $(".step-five").show();
});
$(".step-five-previous").click(function(){
    $(".step-five").hide();
    $(".step-four").show();
});
$(".step-five-next").click(function(){
    $(".step-five").hide();
    $(".step-six").show();
});
$(".step-six-previous").click(function(){
    $(".step-six").hide();
    $(".step-five").show();
});
$(".step-six-next").click(function(){
    $(".step-six").hide();
    $(".step-seven").show();
});
$(".step-seven-previous").click(function(){
    $(".step-seven").hide();
    $(".step-six").show();
});
</script>

So the end goal is to input the inputs at each stage, name the team and then the team names be available in the drop down on the memberTeam <select>

  • 写回答

1条回答 默认 最新

  • doutao4938 2017-01-12 22:03
    关注

    Every time you hit Next button, the form data don't post to server. You can change to <button type="submit" class="step-one-next">Next</button> (add type as submit), but you need to handle which step you're in and which step is next when hit Next. Otherwise, it's easier to use JavaScript.

    Updated using jQuery: https://jsfiddle.net/79nj8e7p/1/

    Sorry, I don't have enough reputation to put as comment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗