在php中将值从一个页面传递到另一个页面

在php中将值从一个页面传递到另一个页面,php,forms,Php,Forms,嗨,我需要实现类似的东西,我有一个ul和li标签中的值列表,在一个页面中,还有一个按钮,所以当我在下一个页面上单击它时,所有这些ul,li值都应该填充到一个选择选项中。 前任。 form1.php <form method="POST" action="next page.php"> <input type="text" name="designation" value="Manager" /> <label>Location:</label> &

嗨,我需要实现类似的东西,我有一个ul和li标签中的值列表,在一个页面中,还有一个按钮,所以当我在下一个页面上单击它时,所有这些ul,li值都应该填充到一个选择选项中。 前任。 form1.php

<form method="POST" action="next page.php">
<input type="text" name="designation" value="Manager" />
<label>Location:</label>
<ul>
<li>New Delhi</li>
<li>Mumbai</li>
</ul>
<input type="submit" value="submit" />
</form>
一旦我提交了form1.php,那么在下一个page.php上应该是这样的

<form method="POST" action="insert.php">
<input type="text" name="designation" value="<?php echo $_POST['designation'] ?>"

<select> all the values from the previos page of ul,li should get populated over here in drop down.</select>
//some more fields will be there in this form.
<input type="text" name="DOB" />
<input type="text" name="phone_no" />

<input type="submit" name="Submit" value="Submit" />

如果用户不打算与之交互,则可以通过隐藏的输入字段在提交时发送位置数据和表单值的其余部分。此任务不需要js/jquery解决方案。您可以添加任意数量的隐藏输入。您可以使用php使其成为动态的,比如说,如果您有一个位置数组可供绘制

<form method="POST" action="next page.php">
    <input type="text" name="designation" value="Manager" />
    <label>Location:</label>
    <ul>
        <li>New Delhi</li>
        <li>Mumbai</li>
    </ul>
    <input type="hidden" name="location[]" value="New Delhi">
    <input type="hidden" name="location[]" value="Mumbai">
    <input type="submit" value="Submit" />
</form>
表格一

    <form method="POST" action="next page.php">
          <input type="text" name="designation" value="Manager" />
          <label>Location:</label>
          <ul>
              <li><input type="hidden" name="city[]" value="New Delhi"></li>
              <li><input type="hidden" name="city[]" value="Mumbai"</li>
         </ul>
         <input type="submit" value="submit" />
   </form>
表格二

     <form method="POST" action="insert.php">
           <input type="text" name="designation" value="<?php echo 
            $_POST['designation'] ?>" >

           <select> 
               <?php foreach($_POST['city'] as $city){ ?>
                     <option><?php echo $city?></option>
               <?php } ?>
           </select>
           //some more fields will be there in this form.
           <input type="text" name="DOB" />
           <input type="text" name="phone_no" />

           <input type="submit" name="Submit" value="Submit" />
    </form>

好吧,我想你应该使用javascript,让我先用jquery,因为ul和li元素不是表单标记的一部分。。。但是:

<form id="form_1" method="POST" action="next_page.php">
    <input type="text" name="test">
    <ul>
        <li>Value 1</li>
        <li>Value 2</li>
        <li>Value 3</li>
    </ul>
    <button type="submit">Do it</button>
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$('#form_1').on('submit',function(e) {
    var ul_li = $(this).find('li');
    ul_li.each(function(index){
        $('<input />').attr('type', 'hidden')
            .attr('name', 'li_'+index)
            .attr('value', $(this).text())
            .appendTo('#form_1');
    }); 
    return true;
});
</script>

您可以在下一页使用$_POST

use-只是一个传递的建议来检索此信息。您可以通过三种不同的方式来检索此信息:将请求URL作为参数,或通过设置cookie,或通过添加会话变量。我正在使用会话,但从ul列表中,li如何在选择、下拉列表中填充这些值,找不到thing@MaxZoom你能分享一个同样的例子吗。我尝试了会话它不起作用你在哪里使用会话?你能发布代码吗?@RiteshSharma我不知道时间戳是否能显示subodhkalika提交答案和我第一篇/未经编辑的帖子的足够详细信息,但他/她的答案与我的答案是晚交的。这就是为什么我否决了它,因为它是我的过程的复制品,从某种意义上说,它是糟糕的形式。
<form id="form_1" method="POST" action="next_page.php">
    <input type="text" name="test">
    <ul>
        <li>Value 1</li>
        <li>Value 2</li>
        <li>Value 3</li>
    </ul>
    <button type="submit">Do it</button>
</form>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script>
$('#form_1').on('submit',function(e) {
    var ul_li = $(this).find('li');
    ul_li.each(function(index){
        $('<input />').attr('type', 'hidden')
            .attr('name', 'li_'+index)
            .attr('value', $(this).text())
            .appendTo('#form_1');
    }); 
    return true;
});
</script>