如何获取数据但保留链接数组

时间:2013-06-02 22:52:46

标签: html forms get

假设我有index.php?couple = old,我想获取新数据(搜索所有“旧”但获取新数据的夫妻),例如

<form action="index.php?couple=old" method="get">
<input type="text" name="search" >
<input type="submit" name="search_btn" />
</form>

有人输入关键字“Smith”应该是index.php?couple = old&amp; search = Smith

2 个答案:

答案 0 :(得分:3)

couple必须是要传递的变量,否则PHP不会将其存储为$_GET的一部分。

你需要:

<form action="index.php" method="get">
<input type="hidden" name="couple" value="old" />
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>

答案 1 :(得分:1)

可能是更好的解决方案(如果你想要使用几个参数)。

<form action="index.php" method="get">
<?php foreach($_GET as $name=>$value):?>
<input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
<?php endforeach;?>
<input type="text" name="search" />
<input type="submit" name="search_btn" />
</form>