嗨我需要实现类似的东西,我在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,然后在下一页.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" />
答案 0 :(得分:0)
如果用户不打算与之交互,您可以通过隐藏的输入字段发送包含其余表单值的位置数据。此任务不需要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>
在下一页$_POST['location'] = array('New Delhi','Mumbai');
,您可以使用以下位置选择创建表单:
<?php
if(isset($_POST['location'])){ // check that this file is receiving POSTed data
echo "<form method=\"POST\" action=\"insert.php\">";
echo "<input type=\"text\" name=\"designation\" value=\"{$_POST['designation']}\" />";
echo "<select name=\"location\">"; // be sure to include name attribute
foreach($_POST['location'] as $loc){
echo "<option>$loc</option>";
}
echo "</select>";
//some more fields will be there in this form.
echo "<input type=\"text\" name=\"DOB\" />";
echo "<input type=\"text\" name=\"phone_no\" />";
echo "<input type=\"submit\" value=\"Submit\" />"; // no name is necessary
echo "</form>";
}
?>
答案 1 :(得分:0)
我猜你应该首先使用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
答案 2 :(得分:-1)
表格1
<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>
表格2
<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>