2013-02-18 47 views
0

這不起作用。舊參數丟失。我得到http://x.x.x.x/temp/test.php?mode=compound如何在PHP中添加現有的url參數提交表單?

<form align="right" action="http://<? echo $_SERVER['SERVER_ADDR']."/temp/test.php?".$_SERVER['QUERY_STRING'];?>"> 
<? if ($_SESSION['mode']=="simple") { ?> 
<input type="submit" value="Switch to compound mode"> 
<input type="hidden" name="mode" value="compound"> 
<? } else { ?> 
<input type="submit" value="Switch to simple mode"> 
<input type="hidden" name="mode" value="simple"> 
<? } ?> 
</form> 

回答

0

我最後用這段代碼做這個代替:

<form align="right" action="http://<?echo $_SERVER['SERVER_ADDR']."/temp/test.php";?>"> 
<? if ($_SESSION['mode']=="simple") { ?> 
<input type="submit" value="Switch to compound mode"> 
<input type="hidden" name="mode" value="compound"> 
<? } else { ?> 
<input type="submit" value="Switch to simple mode"> 
<input type="hidden" name="mode" value="simple"> <? } 
foreach ($_GET as $id=>$parameter) { if ($id=="mode") { continue;}?> 
<input type="hidden" name="<?echo $id;?>" value="<?echo $parameter;?>" /> <? } ?> 
</form> 
0

假設你正在使用GET參數,你可以嘗試使用

echo $_SERVER['SERVER_ADDR']."/temp/test.php?".implode('&', $_GET); 

echo $_SERVER['SERVER_ADDR']."/temp/test.php?".$_SERVER['QUERY_STRING']; 
+0

沒有不行。我仍然得到url http://x.x.x.x/temp/test.php?mode = simple – 2013-02-18 12:32:03

相關問題