2016-10-20 60 views
2

我會盡我所能地盡力解釋這一點。基本上,我使用表單來接收評論。一旦點擊提交,在操作創建一個類似的鏈接:像這樣http://localhost:8080/camagru/comment.php?comment=test&post=Post帶預設變量的HTML帖子表格

我與它的圖像名稱我想通過和一個變量,所以東西:http://localhost:8080/camagru/comment.php?img=test.png&comment=test&post=Post

我試着使用<form action="<?php echo commentpost.php?img=$img?>">但每次按下提交按鈕時,它都會從POST中清除img變量,並僅從表單中放入新變量。

有什麼建議嗎?

+0

你可以把它放在一個隱藏的表單字段。但是,如果它總是一樣的話,就沒有必要發送它。 – jeroen

+0

它總是不同。如何使用預設數據創建隱藏表單字段? – NodziGames

回答

3

形式標記添加新的隱藏字段這樣

<form action="commentpost.php" method="post">  
    <input type="hidden" value="<?php echo $img ?>" name="img" /> 
    <input type="submit" value="Save" name="IsSubmit" /> 
</form> 

現在你可以能夠使用$_POST['img']

+0

謝謝,現在它工作得很好。我很欣賞代碼示例,它使它更易於理解。 – NodziGames

+0

不客氣 –

0

img變量在GET中。

如果你想讓它在開機自檢,儘量<input type="hidden" name="img" value="test.png">

0

使用引號,你的情況:

<form action="<?php echo "commentpost.php?img=$img"; ?>">

最好的做法是隱藏的元素插入到你的形式:

<input name="img1" type="hidden" value="test.png" /> <input name="img2" type="hidden" value="test2.png" />